etl结合java的例子

1.新建Java测试类,导出Jar包,放在kettle目录中的libext文件中

  1. package test; 
  2. public class Test{ 
  3.     public static final String getMyName(String name){ 
  4.         return name+"12345"; 
  5.     } 
  6. }

2.抽数据--经过java处理--输出文件到桌面

  1. import test.Test; 
  2.  
  3. public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException 
  4.     Object[] r = getRow(); 
  5.     if (r == null) { 
  6.         setOutputDone(); 
  7.         return false; 
  8.     } 
  9.  
  10.     if (first) 
  11.     { 
  12.         first = false; 
  13.     } 
  14.  
  15.     // It is always safest to call createOutputRow() to ensure that your output row's Object[] is large 
  16.     // enough to handle any new fields you are creating in this step. 
  17.     //r = createOutputRow(r, outputRowSize); 
  18.      
  19.     /* TODO: Your code here. (See Sample) 
  20.      
  21.     / Get the value from an input field 
  22.     String foobar = get(Fields.In, "a_fieldname").getString(r); 
  23.  
  24.     foobar += "bar"; 
  25.      
  26.     // Set a value in a new output field 
  27.     get(Fields.Out, "output_fieldname").setValue(r, foobar); 
  28.  
  29.     */ 
  30.  
  31.     //调用jar 
  32.     String foobar = get(Fields.In, "ENAME").getString(r); //输入参数 
  33.     foobar += Test.getMyName("我是谁的水"); 
  34.     get(Fields.Out, "ENAME").setValue(r, foobar); 
  35.  
  36.      
  37.     //获取参数 
  38.      String AGEField = getParameter("AGE"); 
  39.      get(Fields.Out, "AGE").setValue(r, AGEField); //输出参数 
  40.      
  41.  
  42.     // Send the row on to the next step. 
  43.     putRow(data.outputRowMeta, r); 
  44.  
  45.     return true; 
  46. }

                  来源:http://programmer.blog.51cto.com/2859493/1164002

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