1. import java.text.DecimalFormat;
  2. public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
  3. if (first) {
  4. first = false;
  5. }
  6. Object[] r = getRow();
  7. if (r == null) {
  8. setOutputDone();
  9. return false;
  10. }
  11. r = createOutputRow(r, data.outputRowMeta.size());
  12. String GMSFHM = get(Fields.In, "GMSFHM").getString(r);
  13. String XM = get(Fields.In, "XM").getString(r);
  14. String YXX = get(Fields.In, "YXX").getString(r);
  15. String rawId = GMSFHM+"_"+XM+"_"+YXX;
  16. int hashCode = rawId.hashCode();
  17. int regionCode = Math.abs(hashCode) % 3;
  18. //格式化分区号
  19. DecimalFormat df = new DecimalFormat("00");
  20. String ID = df.format(regionCode)+"_"+rawId;
  21. get(Fields.Out, "ID").setValue(r, ID);
  22. putRow(data.outputRowMeta, r);
  23. return true;
  24. }

设置参数

image.png

使用参数

  1. int regions = Integer.valueOf(getParameter("regions"));