This function is invoked only after all predecessor nodes have been successfully executed and all data is therefore available at the input ports. Implement this function with your task in the derived model.
The input data is available in the given array argument inData and is ensured to be neither null nor contain null elements. The array index refers to the port index, i.e. if the node has two in-ports, then the BufferedDataTable array consists of two elements: first element (position = 0) the input from the first in-port, second element (position = 1) the input from the second in-port.
In order to create output data, you need to create objects of class BufferedDataTable. Use the ExecutionContext argument to create BufferedDataTable.
The example below demonstrates how to access the data from the in-port.
protectedBufferedDataTable[] execute(finalBufferedDataTable[] inData,finalExecutionContext exec)throwsException { BufferedDataTable table = inData[0];introwCount = table.getRowCount();intcurrentRow = 0;for(DataRow row : table) { // check if the user cancelled the execution exec.checkCanceled(); // report progress exec.setProgress((double)currentRow / rowCount, " processing row " + currentRow);for(inti = 0; i < row.getNumCells(); i++) { DataCell cell = row.getCell(i); if (!cell.isMissing()) { // do something... } } currentRow++; } // return here your results in a BufferedDataTable[] ... }
There are two possibilities to create a new BufferedDataTable for the out-port if new data is generated during the execution of the node:
BufferedDataContainer (Example#2), orColumnRearranger (Example#3)intnrRows = ...;intnrColumns = ...; BufferedDataContainer buf = exec.createBufferedDataContainer(spec);for(intj = 0; j < nrRows; j++) { DataCell[] cells =newDataCell[nrColumns];for(inti = 0; i < nrColumns; i++) { cells[i] =newDoubleCell(i * Math.PI); } DataRow row =newDefaultRow(newStringCell(“RowKey_” + j, cells); buf.addRowToTable(row); } buf.close(); BufferedDataTable table = buf.getTable();
protectedBufferedDataTable[] execute( BufferedDataTable[] inData, ExecutionContext exec)throwsException { DataTableSpec inSpec = inData[0].getDataTableSpec(); ColumnRearranger rearranger = createColumnRearranger(inSpec); BufferedDataTable outTable = exec.createColumnRearrangeTable( inData[0], rearranger, exec);return newBufferedDataTable[]{outTable}; }privateColumnRearranger createColumnRearranger( DataTableSpec spec)throwsInvalidSettingsException { // check user settings against input spec here // fail with InvalidSettingsException if invalid ColumnRearranger result =newColumnRearranger(spec); // the following code appends a single column DataColumnSpecCreator appendSpecCreator =newDataColumnSpecCreator(newName, StringCell.TYPE); DataColumnSpec appendSpec = appendSpecCreator.createSpec(); result.append(newSingleCellFactory(appendSpec) {publicDataCell getCell(finalDataRow row) { // perform calculation based on input row DataCell resultCell =newStringCell( ... )returnresultCell; } });returnresult; }