Search in sources :

Example 21 with StreamableOperator

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

the class CellReplacerNodeModel 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 {
            BufferedDataTable dictTable = (BufferedDataTable) ((PortObjectInput) inputs[1]).getPortObject();
            ColumnRearranger rearranger = createColumnRearranger((DataTableSpec) inSpecs[0], dictTable.getDataTableSpec(), dictTable, exec);
            StreamableFunction func = rearranger.createStreamableFunction(0, 0);
            func.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) BufferedDataTable(org.knime.core.node.BufferedDataTable) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 22 with StreamableOperator

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

the class CategoryToNumberNodeModel 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]);
            cr.createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
            // the optional PMML in port (can be null)
            PMMLPortObject inPMMLPort = null;
            if (m_pmmlInEnabled && inputs[1] != null) {
                inPMMLPort = (PMMLPortObject) ((PortObjectInput) inputs[1]).getPortObject();
            }
            PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, cr.createSpec());
            PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
            for (CategoryToNumberCellFactory factory : m_factories) {
                PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(inPMMLPort));
                outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
            }
            PortObjectOutput portObjectOutput = (PortObjectOutput) outputs[1];
            portObjectOutput.setPortObject(outPMMLPort);
        }
    };
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) PortObjectInput(org.knime.core.node.streamable.PortObjectInput) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) PortObjectOutput(org.knime.core.node.streamable.PortObjectOutput)

Example 23 with StreamableOperator

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

the class ColumnAppenderNodeModel method createStreamableOperator.

// ////////////// STREAMING FUNCTIONS ////////////////
/**
 * {@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 {
            RowInput in1 = (RowInput) inputs[0];
            RowInput in2 = (RowInput) inputs[1];
            RowOutput out = (RowOutput) outputs[0];
            CustomRowIterator tableIt1 = new CustomRowIteratorImpl2(in1);
            CustomRowIterator tableIt2 = new CustomRowIteratorImpl2(in2);
            compute(tableIt1, tableIt2, in1.getDataTableSpec().getNumColumns() + in2.getDataTableSpec().getNumColumns(), row -> {
                out.push(row);
            }, exec, -1, -1);
            // poll all the remaining rows if there are any but don't do anything with them
            while (tableIt1.hasNext()) {
                tableIt1.next();
            }
            while (tableIt2.hasNext()) {
                tableIt2.next();
            }
            in1.close();
            in2.close();
            out.close();
        }
    };
}
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 24 with StreamableOperator

use of org.knime.core.node.streamable.StreamableOperator 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 25 with StreamableOperator

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

the class ReferenceColumnResorterNodeModel method createStreamableOperator.

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

        private String[] m_streamableOperatorOrder;

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            BufferedDataTable orderTable = (BufferedDataTable) ((PortObjectInput) inputs[1]).getPortObject();
            m_streamableOperatorOrder = readOrderFromTable(orderTable);
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            RowInput dataInput = (RowInput) inputs[0];
            DataTableSpec dataInputSpec = dataInput.getDataTableSpec();
            ColumnRearranger rearranger = createColumnRearranger(dataInputSpec, m_streamableOperatorOrder);
            StreamableFunction streamableFunction = rearranger.createStreamableFunction();
            streamableFunction.runFinal(new PortInput[] { dataInput }, outputs, exec);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return createStreamableOperatorInternalsFromOrder(m_streamableOperatorOrder);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_streamableOperatorOrder = readOrderFromStreamableOperatorInternals(internals);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) BufferedDataTable(org.knime.core.node.BufferedDataTable) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) RowInput(org.knime.core.node.streamable.RowInput) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Aggregations

StreamableOperator (org.knime.core.node.streamable.StreamableOperator)57 ExecutionContext (org.knime.core.node.ExecutionContext)56 DataTableSpec (org.knime.core.data.DataTableSpec)32 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)32 RowInput (org.knime.core.node.streamable.RowInput)25 RowOutput (org.knime.core.node.streamable.RowOutput)23 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)23 DataRow (org.knime.core.data.DataRow)13 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)11 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)11 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)10 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)10 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)10 PortObjectInput (org.knime.core.node.streamable.PortObjectInput)8 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)8 PortInput (org.knime.core.node.streamable.PortInput)7 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)6 IOException (java.io.IOException)5 DataCell (org.knime.core.data.DataCell)5