Kettle java脚本代码


我们使用Kettle时,可以比较方便的使用kettle脚本,这个脚本由kettle引入的java引擎执行,下面是一个样例:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {

	if (first) {
    		first = false;
  	}

  	Object[] r = getRow();

  	if (r == null) {
    		setOutputDone();
    		return false;
  	}

  	r = createOutputRow(r, data.outputRowMeta.size());
  	String foobar = get(Fields.In, "NAME").getString(r);

	if("35e8a2c5-3cdf-44d2-ad4c-fedcefcd3b09".equals(get(Fields.In, "ID").getString(r))){
  		System.out.println(get(Fields.In, "NAME").getObject(r).hashCode()+"\r\n");
		String hashSq = "";
		System.out.println(r.length);

		for(int i = 0; i < data.outputRowMeta.getFieldNames().length; ++ i){
			System.out.println(data.outputRowMeta.getFieldNames()[i]);
  			hashSq += get(Fields.In, data.outputRowMeta.getFieldNames()[i]).getObject(r).hashCode();
    			if(i != data.outputRowMeta.getFieldNames().length-1){
				hashSq += ",";
			}
		}
		System.out.println(hashSq);
		System.out.println(Thread.currentThread().getId());
	}

  }

  putRow(data.outputRowMeta, r);

  return true;
}