Search in sources :

Example 16 with RowOutput

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);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableFunction(org.knime.core.node.streamable.StreamableFunction) RowInput(org.knime.core.node.streamable.RowInput)

Example 17 with RowOutput

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;
            }
        };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) StreamableFunction(org.knime.core.node.streamable.StreamableFunction) DataRow(org.knime.core.data.DataRow) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 18 with RowOutput

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 19 with RowOutput

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));
        }
    };
}
Also used : BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) ContainerTable(org.knime.core.data.container.ContainerTable)

Example 20 with RowOutput

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();
            }
        };
    }
}
Also used : NormalizerPortObject(org.knime.base.data.normalize.NormalizerPortObject) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) RowIterator(org.knime.core.data.RowIterator) AffineTransTable(org.knime.base.data.normalize.AffineTransTable) RowInput(org.knime.core.node.streamable.RowInput)

Aggregations

RowOutput (org.knime.core.node.streamable.RowOutput)28 ExecutionContext (org.knime.core.node.ExecutionContext)23 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)23 RowInput (org.knime.core.node.streamable.RowInput)21 DataTableSpec (org.knime.core.data.DataTableSpec)16 DataRow (org.knime.core.data.DataRow)13 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)13 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)9 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 DataCell (org.knime.core.data.DataCell)7 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)6 IOException (java.io.IOException)5 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)5 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)5 File (java.io.File)4 Arrays (java.util.Arrays)4 ReplacedColumnsDataRow (org.knime.base.data.replace.ReplacedColumnsDataRow)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4