etl实现字段值相加

数据库USERS表:

etl步骤:

(2)

(3)

其中java代码为:

    import test.Test;
     
    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
    {
        Object[] r = getRow();
        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.
        //r = createOutputRow(r, outputRowSize);    
        /* TODO: Your code here. (See Sample)         
        / Get the value from an input field
        String foobar = get(Fields.In, "a_fieldname").getString(r);   
        foobar += "bar";       
        // Set a value in a new output field
        get(Fields.Out, "output_fieldname").setValue(r, foobar);   
        */
         //获取参数
        // String AGEField = getParameter("ID");        
        String ID = get(Fields.In, "ID").getString(r); //输入参数  
         get(Fields.Out, "ID").setValue(r, ID); //输出参数
        //调用jar
        String foobar = get(Fields.In, "NAME").getString(r); //输入参数
        foobar += Test.getMyName("我是谁的水");
        get(Fields.Out, "NAME").setValue(r, foobar);
//获取参数
        // String AGEField = getParameter("ID");        
        //String ID = get(Fields.In, "ID").getString(r); //输入参数  
         get(Fields.Out, "aa").setValue(r, "xx"); //输出参数
        // Send the row on to the next step.
        putRow(data.outputRowMeta, r);
        return true;

}

打成jar包丢到kettle目录下:

执行结果:

原文地址:https://www.cnblogs.com/kongxc/p/6247825.html