use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.
the class SplitNodeModel2 method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (m_conf == null) {
m_conf = createColFilterConf();
}
final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
ColumnRearranger[] a = createColumnRearrangers(inSpec);
StreamableFunction func1 = a[0].createStreamableFunction(0, 0);
StreamableFunction func2 = a[1].createStreamableFunction(0, 1);
// use both functions to actually do it
RowInput rowInput = ((RowInput) inputs[0]);
RowOutput rowOutput1 = ((RowOutput) outputs[0]);
RowOutput rowOutput2 = ((RowOutput) outputs[1]);
StreamableFunction.runFinalInterwoven(rowInput, func1, rowOutput1, func2, rowOutput2, exec);
}
};
}
use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.
the class RowKeyNodeModel2 method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
LOGGER.debug("Entering createStreamableOperator-method of class RowKeyNodeModel");
if (m_replaceKey.getBooleanValue()) {
DataTableSpec outSpec = configure((DataTableSpec) inSpecs[DATA_IN_PORT], true);
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
RowInput rowInput = (RowInput) inputs[DATA_IN_PORT];
RowOutput rowOutput = (RowOutput) outputs[DATA_OUT_PORT];
replaceKey(rowInput, rowOutput, outSpec.getNumColumns(), -1, exec);
}
};
} else if (m_appendRowKey.getBooleanValue()) {
LOGGER.debug("The user only wants to append a new column with " + "name " + m_newColumnName);
// the user wants only a column with the given name which
// contains the rowkey as value
final DataTableSpec tableSpec = (DataTableSpec) inSpecs[DATA_IN_PORT];
final String newColumnName = m_newColumnName.getStringValue();
final ColumnRearranger c = RowKeyUtil2.createColumnRearranger(tableSpec, newColumnName, StringCell.TYPE);
return c.createStreamableFunction();
} else {
// the given data
return new StreamableFunction() {
@Override
public DataRow compute(final DataRow input) throws Exception {
return input;
}
};
}
}
use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.
the class RowKeyNodeModel2 method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
LOGGER.debug("Entering execute(inData, exec) of class RowKeyNodeModel");
// check input data
if (inData == null || inData.length != 1 || inData[DATA_IN_PORT] == null) {
throw new IllegalArgumentException("No input data available.");
}
final BufferedDataTable data = inData[DATA_IN_PORT];
BufferedDataTable outData = null;
if (m_replaceKey.getBooleanValue()) {
// create outspec
DataTableSpec outSpec = configure(data.getDataTableSpec(), true);
// create table
final BufferedDataContainer newContainer = exec.createDataContainer(outSpec, true);
RowInput rowInput = new DataTableRowInput(data);
RowOutput rowOutput = new BufferedDataTableRowOutput(newContainer);
replaceKey(rowInput, rowOutput, outSpec.getNumColumns(), data.getRowCount(), exec);
newContainer.close();
outData = newContainer.getTable();
} else if (m_appendRowKey.getBooleanValue()) {
LOGGER.debug("The user only wants to append a new column with " + "name " + m_newColumnName);
// the user wants only a column with the given name which
// contains the rowkey as value
final DataTableSpec tableSpec = data.getDataTableSpec();
final String newColumnName = m_newColumnName.getStringValue();
final ColumnRearranger c = RowKeyUtil2.createColumnRearranger(tableSpec, newColumnName, StringCell.TYPE);
outData = exec.createColumnRearrangeTable(data, c, exec);
exec.setMessage("New column created");
LOGGER.debug("Column appended successfully");
} else {
// the user doesn't want to do anything at all so we simply return
// the given data
outData = data;
LOGGER.debug("The user hasn't selected a new row ID column" + " and hasn't entered a new column name.");
}
LOGGER.debug("Exiting execute(inData, exec) of class RowKeyNodeModel.");
return new BufferedDataTable[] { outData };
}
use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.
the class ReadTableNodeModel 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 {
exec.setMessage("Extract temporary table");
ContainerTable table = extractTable(exec.createSubExecutionContext(0.4));
exec.setMessage("Streaming Output");
RowOutput output = (RowOutput) outputs[0];
execute(table, output, exec.createSubExecutionContext(0.6));
}
};
}
use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.
the class NormalizerApplyNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (getNrOutPorts() == 2) {
// by default call the default implementation of this method
return super.createStreamableOperator(partitionInfo, inSpecs);
} else {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
assert outputs.length == 1;
NormalizerPortObject model = (NormalizerPortObject) ((PortObjectInput) inputs[0]).getPortObject();
RowInput rowInput = (RowInput) inputs[1];
AffineTransTable t = new AffineTransTable(rowInput, getAffineTrans(model.getConfiguration()));
RowOutput rowOutput = (RowOutput) outputs[0];
RowIterator it = t.iterator();
while (it.hasNext()) {
rowOutput.push(it.next());
}
if (t.getErrorMessage() != null) {
// TODO collect error message from remote nodes if run distributed
setWarningMessage(t.getErrorMessage());
}
rowInput.close();
rowOutput.close();
}
};
}
}
Aggregations