多语言展示
当前在线:845今日阅读:176今日分享:34

kettle 中“Java代码”组件的使用方法

在利用kettle 对数据进行处理时往往碰到 第二行数据的空值就是第一行的数据,以此类比,只要某一行为空值,往往需要复制上一行数据的值,下面就为大家讲解一下利用Java组件 对这一数据进行处理的方法。如图分别是源数据和需要处理后的数据格式
方法/步骤
2

2.选择“Java代码”;String xuhaotemp;String chanpintemp;public boolean processRow(StepMetaInterface smi, StepDataInterface sdi)  throws KettleException{    // First, get a row from the default input hop    Object[] r = getRow();    // If the row object is null, we are done processing.    if (r == null) {      setOutputDone();      return false;    }    if (first){      first = false;    }        // It is always safest to call createOutputRow() to ensure that your output row's Object[] is large    // enough to handle any new fields you are creating in this step.    Object[] outputRow = createOutputRow(r, data.outputRowMeta.size());        String xuhao = get(Fields.In, 'Number').getString(r);    String chanpin = get(Fields.In, 'NumCode').getString(r);    // Set the value in the output field    String newxuhao = '';    String newchanpin = '';    if (xuhao == null)    {        newxuhao = xuhaotemp;    }    else    {        newxuhao = xuhao;        xuhaotemp = xuhao;    }    if (chanpin == null)    {        newchanpin = chanpintemp;    }    else    {        newchanpin = chanpin;        chanpintemp = chanpin;    }    get(Fields.Out, 'newxuhao').setValue(outputRow, newxuhao);    get(Fields.Out, 'newchanpin').setValue(outputRow, newchanpin);    // putRow will send the row on to the default output hop.    putRow(data.outputRowMeta, outputRow);    return true;}

3

结果流程:

推荐信息