it is the second time that i ask about this topic,
I have an array , i need to put it in bufferedReader to get the result in the output of the node.
i tried to work with the Rearrenger , and ListCell, but it appends my column and the the data in port , but i just need to have my column in outport.
return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[IN_PORT], rearranger, exec) };
The rearranger is just a convenience class (use it where you can, b/c you get threading and streaming and all this neatness with little coding effort). The ColumnRearranger also allows to hide certain input columns, probably that makes sense in your case, check its API.
But you can also build your output table from ground up "by foot" simply by appending to a BufferedDataContainer (that's what you probably mean by "BufferedReader"???).
BufferedDataContainer container = exec.createDataContainer(spec);
// probably in a loop; then don't forget to invoke
// exec.checkCanceled() and exec.setProgress(…)
container.addRowToTable(…);
container.close();
BufferedDataTable table = container.getTable();
i want to browse a matrix in order to display a few lignes in the output port. I think that i have to convert it into DataTable to use the Row Iterator, but i didn't succed to do it.
Here is example code which don't make use of column rearranger to create an output table of a matrix of doubles.
//here we suppose to have a matrix of doubles
double[][] matrix;
static DataTableSpec createOutTableSpec(final int numCols) {
final DataColumnSpec[] colSpecs = new DataColumnSpec[numCols];
for (int i=0; i<numCols; i++)
colSpecs[i] = new DataColumnSpecCreator(String.format("Col %d", i), DoubleCell.TYPE).createSpec();
return new DataTableSpec("My output table", colSpecs);
}
@Override
protected DataTableSpec[] configure(DataTableSpec[] inSpecs)
throws InvalidSettingsException {
//here we assume matrix is not null and it has at least one row
return createOutTableSpec(matrix[0].length);
}
@Override
protected BufferedDataTable[] execute(BufferedDataTable[] inData,
ExecutionContext exec)
throws Exception {
final int numRows = matrix.length;
if (numRows == 0)
throw new Exception("Empty matrix");
final int numCols = matrix[0].length;
final DataTableSpec outTableSpec = createOutTableSpec(numCols);
BufferedDataContainer container = exec.createDataContainer(spec);
for (int row=0; row < numRows; row++)
container.addRowToTable(new DefaultRow(RowKey.createRowKey((long)row), matrix[row])));
container.close();
BufferedDataTable table = container.getTable();
return new BufferedDataTable[] { table };
}
I have not tested it, just written here as example. Modify it accordingly to your needs.