Well, my node permits to choose a column.
This column must be split into N exits depending on the value
Example table:
column "RAPP01" type string values (aa,bb,aa,cc)
column "date" type date values (2014-10-10,2014-10-10,2014-10-10,?)
the ? is an empty cell
result table 1
mod_aa/2014-10-10
mod_aa/2014-10-10
result table 2
mod_bb/2014-10-10
result table 3
mod_cc/?
all others are empty tables...
I can do this implementation without to modify the input and all work.
Now i need to edit the column named RAPP and this is the problem because i must replicate the missing values.
Some hints to improve performance of this code is well-accepted =)
protected BufferedDataTable[] execute(final BufferedDataTable[] inData,
final ExecutionContext exec) throws Exception {
NodeLogger n = NodeLogger.getLogger(SplitterDQNodeModel.class);
DataTableSpec inSpec = inData[0].getDataTableSpec();
ArrayList<BufferedDataContainer> buf = new ArrayList<BufferedDataContainer>();
for(int i=0;i<EXIT;i++)
buf.add(exec.createDataContainer(inSpec));
int column_index = inSpec.findColumnIndex(m_colSel.getStringValue());
String[] column = inSpec.getColumnNames();
ArrayList<Integer> index_column_rapp= new ArrayList<Integer>();
for(int i=0;i<column.length;i++)
{
if(column[i].toUpperCase().indexOf("RAPP")!=-1)
index_column_rapp.add(i);
if(inSpec.getColumnSpec(i).getType().toString().equals("IntCell"))
index_column_int.add(i);
if(inSpec.getColumnSpec(i).getType().toString().equals("DoubleCell"))
index_column_double.add(i);
if(inSpec.getColumnSpec(i).getType().toString().equals("DateAndTimeCell"))
index_column_data.add(i);
}
int count = 0;
final int nrRows = inData[0].getRowCount();
ArrayList<String> list_value=new ArrayList<String>();
for (DataRow row : inData[0]) {
int nrColumns = row.getNumCells();
DataCell[] cells = new DataCell[nrColumns];
for (int i = 0; i < nrColumns; i++) {
String current_value = row.getCell(i).toString();
if(index_column_rapp.contains(i))
current_value = U_rappID(current_value);
cells[i] = new StringCell(current_value);
if(index_column_int.contains(i))
{if(!current_value.equals("?"))
cells[i] = new IntCell(Integer.parseInt(current_value));
else
cells[i] = new IntCell(0);
}
else
if(index_column_double.contains(i))
{if(!current_value.equals("?"))
cells[i] = new DoubleCell(Double.parseDouble(current_value));
else
cells[i] = new DoubleCell(0.0d);
}
else
if(index_column_data.contains(i))
{if(!current_value.equals("?"))
{
int year=Integer.parseInt(current_value.substring(0,4));
int month=Integer.parseInt(current_value.substring(5,7));
int day=Integer.parseInt(current_value.substring(8,10));
cells[i] = new DateAndTimeCell(year,month-1,day);
}
else
cells[i] = new DateAndTimeCell(1000, 0, 1);
}
}
DataRow new_row = new DefaultRow(row.getKey(), cells);
String current_value=row.getCell(column_index).toString();
int index = list_value.indexOf(current_value);
if(index==-1)
{
if(list_value.size()<EXIT)
{buf.get(list_value.size()).addRowToTable(new_row);
list_value.add(current_value);
}
else
{
buf.get(EXIT-1).addRowToTable(new_row);
}
}
else
buf.get(index).addRowToTable(new_row);
exec.checkCanceled();
exec.setProgress(count / (double) nrRows,
"Added row " + (++count) + "/" + nrRows + " (\""
+ row.getKey() + "\")");
}
BufferedDataTable[] out = new BufferedDataTable[EXIT];
for(int i=0;i<EXIT;i++) {
buf.get(i).close();
out[i]=buf.get(i).getTable();
}
return out;
}