use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.
the class FilterApplyNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
exec.setProgress(0);
PortObject portObject = inObjects[1];
DataTableSpec filterSpec = portObject == null ? ((BufferedDataTable) inObjects[0]).getDataTableSpec() : ((FilterDefinitionHandlerPortObject) portObject).getSpec();
final BufferedDataTableRowOutput out = new BufferedDataTableRowOutput(exec.createDataContainer(((BufferedDataTable) inObjects[0]).getDataTableSpec()));
execute(new DataTableRowInput((BufferedDataTable) inObjects[0]), out, filterSpec, exec, ((BufferedDataTable) inObjects[0]).size());
return new BufferedDataTable[] { out.getDataTable() };
}
use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.
the class FilterApplyNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final DataTableRowInput in = (DataTableRowInput) inputs[0];
final RowOutput out = (RowOutput) outputs[0];
PortObjectInput portObjectInput = (PortObjectInput) inputs[1];
DataTableSpec filterSpec = portObjectInput == null ? in.getDataTableSpec() : ((FilterDefinitionHandlerPortObject) portObjectInput.getPortObject()).getSpec();
FilterApplyNodeModel.this.execute(in, out, filterSpec, exec, -1);
}
};
}
use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.
the class RowFilter2PortNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable in = inData[0];
// in case the node was configured and the workflow is closed
// (and saved), the row filter isn't configured upon reloading.
// here, we give it a chance to configure itself (e.g. find the column
// index)
m_rowFilter.configure(in.getDataTableSpec());
BufferedDataContainer match = exec.createDataContainer(in.getDataTableSpec());
BufferedDataContainer miss = exec.createDataContainer(in.getDataTableSpec());
RowOutput rowOutput1 = new BufferedDataTableRowOutput(match);
RowOutput rowOutput2 = new BufferedDataTableRowOutput(miss);
RowInput rowInput = new DataTableRowInput(inData[0]);
// do it
this.execute(rowInput, rowOutput1, rowOutput2, inData[0].size(), exec);
// note: tables are closed in the private execute method
return new BufferedDataTable[] { match.getTable(), miss.getTable() };
}
use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.
the class ConcatenateTableFactory method addTable.
/**
* Table is added and rows are copied to a new data container. Creates a new data container if this data table spec
* differs from the previous table. This method call checks for row keys duplicates and throws a
* {@link DuplicateKeyException}.
*
* @param table the table to be added
* @param exec the execution context to possibly create a new data container
* @throws InterruptedException
* @throws IOException
* @throws DuplicateKeyException
* @throws CanceledExecutionException
*/
void addTable(final BufferedDataTable table, final ExecutionContext exec) throws InterruptedException, DuplicateKeyException, IOException, CanceledExecutionException {
DataTableRowInput rowInput = new DataTableRowInput(table);
addTable(rowInput, exec);
rowInput.close();
}
use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.
the class CSVWriter method write.
/**
* Same as above just usable with a streaming node implementation.
* @param input
* @param exec
* @throws IOException
* @throws CanceledExecutionException
* @throws InterruptedException
* @since 2.12
*/
public void write(final RowInput input, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, InterruptedException {
DataTableSpec inSpec = input.getDataTableSpec();
final int colCount = inSpec.getNumColumns();
// if first entry in the row (skip separator then)
boolean first;
// reset any previous warning
m_lastWarning = null;
// write column names
if (m_settings.writeColumnHeader()) {
if (m_settings.writeRowID()) {
// RowHeader header
write(quoteString("row ID", false));
first = false;
} else {
first = true;
}
for (int i = 0; i < colCount; i++) {
String cName = inSpec.getColumnSpec(i).getName();
if (!first) {
write(m_settings.getColSeparator());
}
first = false;
write(quoteString(cName, false));
}
newLine();
}
// end of if write column names
// write each row of the data
int i = 0;
long rowCnt = -1;
if (input instanceof DataTableRowInput) {
rowCnt = ((DataTableRowInput) input).getRowCount();
}
DataRow row;
while ((row = input.poll()) != null) {
String rowKey = row.getKey().toString();
String msg;
// set the progress
if (rowCnt <= 0) {
msg = "Writing row " + (i + 1) + " (\"" + rowKey + "\")";
} else {
msg = "Writing row " + (i + 1) + " (\"" + rowKey + "\") of " + rowCnt;
exec.setProgress(i / (double) rowCnt, msg);
}
// Check if execution was canceled !
exec.checkCanceled();
// write the columns
first = true;
// first, the row id
if (m_settings.writeRowID()) {
write(quoteString(row.getKey().getString(), false));
first = false;
}
// now all data cells
for (int c = 0; c < colCount; c++) {
DataCell colValue = row.getCell(c);
if (!first) {
write(m_settings.getColSeparator());
}
first = false;
if (colValue.isMissing()) {
// never quote missing patterns.
write(m_settings.getMissValuePattern());
} else {
boolean isNumerical = false;
DataType type = inSpec.getColumnSpec(c).getType();
String strVal = colValue.toString();
if (type.isCompatible(DoubleValue.class)) {
isNumerical = true;
}
if (isNumerical && (m_settings.getDecimalSeparator() != '.')) {
// contained in the value.
if (strVal.indexOf(m_settings.getDecimalSeparator()) < 0) {
strVal = replaceDecimalSeparator(strVal, m_settings.getDecimalSeparator());
} else {
if (m_lastWarning == null) {
m_lastWarning = "Specified decimal separator ('" + m_settings.getDecimalSeparator() + "') is" + " contained in the numerical value. " + "Not replacing decimal separator (e.g. " + "in row #" + i + " column #" + c + ").";
}
}
}
write(quoteString(strVal, isNumerical));
}
}
newLine();
i++;
}
}
Aggregations