Search in sources :

Example 6 with RowOutput

use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.

the class LagColumnStreamableOperator method runFinal.

/**
 * {@inheritDoc}
 */
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
    long counter = 0;
    int maxLag = m_configuration.getLagInterval() * m_configuration.getLag();
    RingBuffer ringBuffer = new RingBuffer(maxLag);
    RowInput input = (RowInput) inputs[0];
    RowOutput output = (RowOutput) outputs[0];
    int skippedFirstCount = !m_configuration.isSkipInitialIncompleteRows() ? -1 : m_configuration.getLagInterval() * m_configuration.getLag();
    DataRow row;
    while ((row = input.poll()) != null) {
        if (counter >= skippedFirstCount) {
            DataCell[] newCells = getAdditionalCells(ringBuffer);
            output.push(copyWithNewCells(row, newCells));
        }
        DataCell toBeCached = m_columnIndex < 0 ? new StringCell(row.getKey().toString()) : row.getCell(m_columnIndex);
        ringBuffer.add(toBeCached);
        setProgress(exec, counter, row);
        counter += 1;
    }
    if (!m_configuration.isSkipLastIncompleteRows()) {
        DataCell[] missings = new DataCell[input.getDataTableSpec().getNumColumns()];
        Arrays.fill(missings, DataType.getMissingCell());
        for (int i = 0; i < maxLag; i++) {
            DataRow missingRow = new DefaultRow("overflow-" + i, missings);
            DataCell[] newCells = getAdditionalCells(ringBuffer);
            output.push(copyWithNewCells(missingRow, newCells));
            ringBuffer.add(DataType.getMissingCell());
        }
    }
    output.close();
}
Also used : RowOutput(org.knime.core.node.streamable.RowOutput) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) RowInput(org.knime.core.node.streamable.RowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) DataRow(org.knime.core.data.DataRow)

Example 7 with RowOutput

use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.

the class RowFilterNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        @Override
        public StreamableOperatorInternals saveInternals() {
            return null;
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext ctx) throws Exception {
            RowInput in = (RowInput) inputs[0];
            RowOutput out = (RowOutput) outputs[0];
            RowFilterNodeModel.this.execute(in, out, ctx);
        }
    };
}
Also used : RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) RowInput(org.knime.core.node.streamable.RowInput)

Example 8 with RowOutput

use of org.knime.core.node.streamable.RowOutput in project knime-core by knime.

the class AbstractColumnRefNodeModel 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 {
            ColumnRearranger[] cr = createRearranger((DataTableSpec) inSpecs[0], (DataTableSpec) inSpecs[1]);
            StreamableFunction func1 = cr[0].createStreamableFunction(0, 0);
            if (m_isSplitter) {
                StreamableFunction func2 = cr[1].createStreamableFunction(0, 1);
                RowInput rowInput = ((RowInput) inputs[0]);
                RowOutput rowOutput1 = ((RowOutput) outputs[0]);
                RowOutput rowOutput2 = ((RowOutput) outputs[1]);
                StreamableFunction.runFinalInterwoven(rowInput, func1, rowOutput1, func2, rowOutput2, exec);
            } else {
                func1.runFinal(inputs, outputs, exec);
            }
        }
    };
}
Also used : 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 9 with RowOutput

use of org.knime.core.node.streamable.RowOutput 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);
        }
    };
}
Also used : BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) PortObjectInput(org.knime.core.node.streamable.PortObjectInput)

Example 10 with RowOutput

use of org.knime.core.node.streamable.RowOutput 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() };
}
Also used : BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

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