0
我需要執行以下操作。 提供的輸入是如下所示在PDI中使用UDJC步驟處理多個輸入行
State city
NY joe
NY jane
LA zorro
LA steve
和輸出應該是
State city
NY joe, jane
LA steve, zorro
如何使這成爲可能?我想我必須處理多個輸入行,但是當我嘗試使用getRow()
方法第二次讀取新行時,它將拋出數組超出範圍異常....請幫助我解決此問題。TIA
下面是我試過的邏輯...
String cities;
Object[][] r = new Object[10][];
static int j;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
for(;j<10||(r[j]=getRow())!=null;j++)
{
return true;
}
cities=get(Fields.In, "CITY").getString(r[0]);
int i;
for(i=1;r[i]!=null;i++)
{
if(get(Fields.In, "STATE").getString(r[i-1])==get(Fields.In, "STATE").getString(r[i])){
cities=cities+","+get(Fields.In, "CITY").getString(r[i]);
}
else{
Object[] outputRow = createOutputRow(new Object[4],1);
get(Fields.Out, "STATE").setValue(outputRow, get(Fields.In, "STATE").getString(r[i-1]));
get(Fields.Out, "CITIES").setValue(outputRow, cities);
putRow(data.outputRowMeta, outputRow);
cities=get(Fields.In, "CITY").getString(r[i]);
}
}
Object[] outputRow = createOutputRow(new Object[4],1);
get(Fields.Out, "STATE").setValue(outputRow, get(Fields.In, "STATE").getString(r[i-1]));
get(Fields.Out, "CITIES").setValue(outputRow, cities);
putRow(data.outputRowMeta, outputRow);
return false;
}