Search in sources :

Example 1 with PortObjectOutput

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

the class RuleEngine2PortsNodeModel method createStreamableOperator.

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

        private StreamInternalWithPortObject m_internals;

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

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            // count number of rows
            long count = 0;
            final RowInput rowInput = (RowInput) inputs[DATA_PORT];
            while (rowInput.poll() != null) {
                count++;
            }
            if (inputs[RULE_PORT] instanceof RowInput) {
                final RowInput ruleInput = (RowInput) inputs[RULE_PORT];
                final Pair<ColumnRearranger, PortObject> pair = createColumnRearranger(rowInput.getDataTableSpec(), ruleInput);
                final ColumnRearranger rearranger = pair.getFirst();
                final DataTableSpec spec = rearranger.createSpec();
                m_internals.setTableSpec(spec);
                if (pair.getSecond() instanceof PMMLPortObject) {
                    PMMLPortObject po = (PMMLPortObject) pair.getSecond();
                    m_internals.setObject(po);
                } else {
                    m_internals.setObject(null);
                }
            }
            m_internals.setRowCount(count);
        }

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

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            if (m_internals.getTableSpec() != null) {
                m_rowCount = m_internals.getRowCount();
            }
            final Pair<ColumnRearranger, PortObject> pair = createColumnRearranger((DataTableSpec) inSpecs[DATA_PORT], (RowInput) inputs[RULE_PORT]);
            pair.getFirst().createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
            if (pair.getSecond() != null) {
                ((PortObjectOutput) outputs[1]).setPortObject(pair.getSecond());
            }
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) 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) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) PortObject(org.knime.core.node.port.PortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortObjectOutput(org.knime.core.node.streamable.PortObjectOutput)

Example 2 with PortObjectOutput

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

the class PMMLRuleEditorNodeModel method finishStreamableExecution.

/**
 * {@inheritDoc}
 */
@Override
public void finishStreamableExecution(final StreamableOperatorInternals internals, final ExecutionContext exec, final PortOutput[] output) throws Exception {
    final StreamInternalForPMMLPortObject poInternals = (StreamInternalForPMMLPortObject) internals;
    PMMLPortObject ret = poInternals.getObject();
    ret.validate();
    ((PortObjectOutput) output[1]).setPortObject(ret);
}
Also used : PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObjectOutput(org.knime.core.node.streamable.PortObjectOutput)

Example 3 with PortObjectOutput

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

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

the class DataColumnSpecFilterPMMLNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final ColumnRearranger corea = createColumnRearranger((DataTableSpec) inSpecs[0]);
    final StreamableFunction fct = corea.createStreamableFunction();
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            // execute streamable in- and outport (0)
            fct.init(exec);
            fct.runFinal(inputs, outputs, exec);
            fct.finish();
            DataTableSpec outSpec = corea.createSpec();
            // pmml ports
            PMMLPortObject pmmlIn = (PMMLPortObject) ((PortObjectInput) inputs[1]).getPortObject();
            final PMMLPortObject pmmlOut = createPMMLOut(pmmlIn, outSpec, getFilterResult((DataTableSpec) inSpecs[0]));
            ((PortObjectOutput) outputs[1]).setPortObject(pmmlOut);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ExecutionContext(org.knime.core.node.ExecutionContext) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableFunction(org.knime.core.node.streamable.StreamableFunction) PortObjectOutput(org.knime.core.node.streamable.PortObjectOutput)

Example 5 with PortObjectOutput

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

the class VirtualSubNodeInputNodeModel method createStreamableOperator.

@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 {
            assert inputs.length == 0;
            PortObject[] dataFromParent = ArrayUtils.remove(m_subNodeContainer.fetchInputDataFromParent(), 0);
            for (int i = 0; i < outputs.length; i++) {
                if (BufferedDataTable.TYPE.equals(getOutPortType(i))) {
                    // stream port content if it's data
                    BufferedDataTable bdt = (BufferedDataTable) (dataFromParent[i]);
                    RowOutput rowOutput = (RowOutput) outputs[i];
                    for (DataRow dr : bdt) {
                        rowOutput.push(dr);
                    }
                    rowOutput.close();
                } else {
                    ((PortObjectOutput) outputs[i]).setPortObject(dataFromParent[i]);
                }
            }
        }
    };
}
Also used : RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) BufferedDataTable(org.knime.core.node.BufferedDataTable) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortObject(org.knime.core.node.port.PortObject) DataRow(org.knime.core.data.DataRow) PortObjectOutput(org.knime.core.node.streamable.PortObjectOutput)

Aggregations

PortObjectOutput (org.knime.core.node.streamable.PortObjectOutput)6 ExecutionContext (org.knime.core.node.ExecutionContext)5 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)5 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)5 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 DataTableSpec (org.knime.core.data.DataTableSpec)2 PortObject (org.knime.core.node.port.PortObject)2 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)2 PortObjectInput (org.knime.core.node.streamable.PortObjectInput)2 DataRow (org.knime.core.data.DataRow)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)1 DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)1 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)1 RowInput (org.knime.core.node.streamable.RowInput)1 RowOutput (org.knime.core.node.streamable.RowOutput)1 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)1 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)1