Search in sources :

Example 21 with SimpleStreamableOperatorInternals

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

the class RuleEngineFilterNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec spec = (DataTableSpec) inSpecs[0];
    try {
        parseRules(spec, RuleNodeSettings.RuleFilter);
    } catch (final ParseException e) {
        throw new InvalidSettingsException(e);
    }
    return new StreamableOperator() {

        private SimpleStreamableOperatorInternals m_internals;

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_internals = (SimpleStreamableOperatorInternals) internals;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            // count number of rows
            long count = 0;
            if (inputs[0] instanceof RowInput) {
                final RowInput rowInput = (RowInput) inputs[0];
                while (rowInput.poll() != null) {
                    count++;
                }
            } else if (inputs[0] instanceof PortObjectInput) {
                final PortObjectInput portObjectInput = (PortObjectInput) inputs[0];
                count += ((BufferedDataTable) portObjectInput.getPortObject()).size();
            }
            m_internals.getConfig().addLong(CFG_ROW_COUNT, count);
        }

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

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            long rowCount = -1L;
            if (m_internals.getConfig().containsKey(CFG_ROW_COUNT)) {
                rowCount = m_internals.getConfig().getLong(CFG_ROW_COUNT);
            }
            RowOutput[] rowOutputs = (outputs instanceof RowOutput[]) ? (RowOutput[]) outputs : outputs.length > 1 ? new RowOutput[] { (RowOutput) outputs[0], (RowOutput) outputs[1] } : new RowOutput[] { (RowOutput) outputs[0] };
            execute((RowInput) inputs[0], rowOutputs, rowCount, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) PortObjectInput(org.knime.core.node.streamable.PortObjectInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) ParseException(java.text.ParseException)

Example 22 with SimpleStreamableOperatorInternals

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

the class RuleEngineNodeModel method createMergeOperator.

/**
 * {@inheritDoc}
 */
@Override
public MergeOperator createMergeOperator() {
    return new MergeOperator() {

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals mergeIntermediate(final StreamableOperatorInternals[] operators) {
            // sum up the row counts if necessary
            long count = 0;
            for (int i = 0; i < operators.length; i++) {
                SimpleStreamableOperatorInternals simpleInternals = (SimpleStreamableOperatorInternals) operators[i];
                CheckUtils.checkState(simpleInternals.getConfig().containsKey(CFG_ROW_COUNT), "Config for key " + CFG_ROW_COUNT + " isn't set.");
                try {
                    count += simpleInternals.getConfig().getLong(CFG_ROW_COUNT);
                } catch (InvalidSettingsException e) {
                    // should not happen since we checked already
                    throw new RuntimeException(e);
                }
            }
            SimpleStreamableOperatorInternals res = new SimpleStreamableOperatorInternals();
            if (count > 0) {
                res.getConfig().addLong(CFG_ROW_COUNT, count);
            }
            return res;
        }

        @Override
        public StreamableOperatorInternals mergeFinal(final StreamableOperatorInternals[] operators) {
            // nothing to do here
            return null;
        }
    };
}
Also used : SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) MergeOperator(org.knime.core.node.streamable.MergeOperator)

Example 23 with SimpleStreamableOperatorInternals

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

the class JavaRowSplitterNodeModel method saveLong.

private static SimpleStreamableOperatorInternals saveLong(final long rowCount) {
    SimpleStreamableOperatorInternals internals = new SimpleStreamableOperatorInternals();
    internals.getConfig().addLong(SIMPLE_STREAMABLE_ROWCOUNT_KEY, rowCount);
    return internals;
}
Also used : SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)

Example 24 with SimpleStreamableOperatorInternals

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

the class AbstractConditionalStreamingNodeModel method createStreamableOperator.

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

        private SimpleStreamableOperatorInternals m_internals;

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_internals = (SimpleStreamableOperatorInternals) internals;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            // count number of rows
            long count = 0;
            RowInput rowInput = (RowInput) inputs[0];
            while (rowInput.poll() != null) {
                count++;
            }
            m_internals.getConfig().addLong(CFG_ROW_COUNT, count);
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            long rowCount = -1;
            if (m_internals.getConfig().containsKey(CFG_ROW_COUNT)) {
                rowCount = m_internals.getConfig().getLong(CFG_ROW_COUNT);
            }
            StreamableFunction func = createColumnRearranger((DataTableSpec) inSpecs[0], rowCount).createStreamableFunction();
            func.runFinal(inputs, outputs, exec);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return m_internals;
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) 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

SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)24 DataTableSpec (org.knime.core.data.DataTableSpec)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 BufferedDataTable (org.knime.core.node.BufferedDataTable)7 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)7 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)7 ExecutionContext (org.knime.core.node.ExecutionContext)6 RowInput (org.knime.core.node.streamable.RowInput)6 Config (org.knime.core.node.config.Config)5 MergeOperator (org.knime.core.node.streamable.MergeOperator)5 DataColumnSpec (org.knime.core.data.DataColumnSpec)4 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)4 DataRow (org.knime.core.data.DataRow)4 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)4 PortInput (org.knime.core.node.streamable.PortInput)4 RowOutput (org.knime.core.node.streamable.RowOutput)4 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3 PartitionInfo (org.knime.core.node.streamable.PartitionInfo)3 PortOutput (org.knime.core.node.streamable.PortOutput)3