Search in sources :

Example 76 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class MLPPredictorNodeModel 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 {
            PMMLPortObject pmmlPortObject = (PMMLPortObject) ((PortObjectInput) inputs[0]).getPortObject();
            ColumnRearranger colre = createColumnRearranger(pmmlPortObject, (DataTableSpec) inSpecs[1]);
            StreamableFunction func = colre.createStreamableFunction(1, 0);
            func.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : 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) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 77 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class LoopEnd2NodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    if (!(this.getLoopStartNode() instanceof LoopStartNodeTerminator)) {
        throw new IllegalStateException("Loop end is not connected" + " to matching/corresponding loop start node. You" + "are trying to create an infinite loop!");
    }
    if (m_tableFactories[0] == null) {
        // first iteration -> create table factories
        Optional<Function<RowKey, RowKey>> rowKeyFunc1;
        Optional<Function<RowKey, RowKey>> rowKeyFunc2;
        switch(m_settings.rowKeyPolicy()) {
            case APPEND_SUFFIX:
                rowKeyFunc1 = Optional.of(k -> {
                    return new RowKey(k.toString() + "#" + (m_iteration));
                });
                rowKeyFunc2 = Optional.of(k -> {
                    return new RowKey(k.toString() + "#" + (m_iteration));
                });
                break;
            case GENERATE_NEW:
                rowKeyFunc1 = Optional.of(k -> {
                    return new RowKey("Row" + (m_count1++));
                });
                rowKeyFunc2 = Optional.of(k -> {
                    return new RowKey("Row" + (m_count2++));
                });
                break;
            case UNMODIFIED:
            default:
                rowKeyFunc1 = Optional.empty();
                rowKeyFunc2 = Optional.empty();
        }
        m_tableFactories[0] = new ConcatenateTableFactory(m_settings.ignoreEmptyTables1(), m_settings.tolerateColumnTypes1(), m_settings.addIterationColumn(), m_settings.tolerateChangingTableSpecs1(), rowKeyFunc1);
        m_tableFactories[1] = new ConcatenateTableFactory(m_settings.ignoreEmptyTables2(), m_settings.tolerateColumnTypes2(), m_settings.addIterationColumn(), m_settings.tolerateChangingTableSpecs2(), rowKeyFunc2);
    }
    // add tables to factories
    m_tableFactories[0].addTable(inData[0], exec);
    m_tableFactories[1].addTable(inData[1], exec);
    final boolean terminateLoop = ((LoopStartNodeTerminator) this.getLoopStartNode()).terminateLoop();
    if (terminateLoop) {
        m_iteration = 0;
        m_count1 = 0;
        m_count2 = 0;
        BufferedDataTable[] outTables = new BufferedDataTable[2];
        outTables[0] = m_tableFactories[0].createTable(exec);
        outTables[1] = m_tableFactories[1].createTable(exec);
        return outTables;
    } else {
        continueLoop();
        m_iteration++;
        return new BufferedDataTable[2];
    }
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) RowKey(org.knime.core.data.RowKey) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) LoopEndNode(org.knime.core.node.workflow.LoopEndNode) IOException(java.io.IOException) NodeModel(org.knime.core.node.NodeModel) Function(java.util.function.Function) LoopStartNodeTerminator(org.knime.core.node.workflow.LoopStartNodeTerminator) File(java.io.File) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) ExecutionContext(org.knime.core.node.ExecutionContext) BufferedDataTable(org.knime.core.node.BufferedDataTable) Optional(java.util.Optional) Function(java.util.function.Function) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) LoopStartNodeTerminator(org.knime.core.node.workflow.LoopStartNodeTerminator)

Example 78 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class LoopEndNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    if (!(this.getLoopStartNode() instanceof LoopStartNodeTerminator)) {
        throw new IllegalStateException("Loop End is not connected" + " to matching/corresponding Loop Start node. You" + " are trying to create an infinite loop!");
    }
    if (m_tableFactory == null) {
        // first time we get here: create table factory
        Optional<Function<RowKey, RowKey>> rowKeyFunc;
        switch(m_settings.rowKeyPolicy()) {
            case APPEND_SUFFIX:
                rowKeyFunc = Optional.of(k -> {
                    return new RowKey(k.toString() + "#" + (m_iteration));
                });
                break;
            case GENERATE_NEW:
                rowKeyFunc = Optional.of(k -> {
                    return new RowKey("Row" + (m_count++));
                });
                break;
            case UNMODIFIED:
            default:
                rowKeyFunc = Optional.empty();
        }
        m_tableFactory = new ConcatenateTableFactory(m_settings.ignoreEmptyTables(), m_settings.tolerateColumnTypes(), m_settings.addIterationColumn(), m_settings.tolerateChangingTableSpecs(), rowKeyFunc);
        m_startTime = System.currentTimeMillis();
    }
    m_tableFactory.addTable(inData[0], exec);
    boolean terminateLoop = ((LoopStartNodeTerminator) this.getLoopStartNode()).terminateLoop();
    if (terminateLoop) {
        LOGGER.debug("Total loop execution time: " + (System.currentTimeMillis() - m_startTime) + "ms");
        m_startTime = 0;
        m_iteration = 0;
        m_count = 0;
        return new BufferedDataTable[] { m_tableFactory.createTable(exec) };
    } else {
        m_iteration++;
        continueLoop();
        return new BufferedDataTable[1];
    }
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) RowKey(org.knime.core.data.RowKey) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) LoopEndNode(org.knime.core.node.workflow.LoopEndNode) IOException(java.io.IOException) NodeModel(org.knime.core.node.NodeModel) Function(java.util.function.Function) LoopStartNodeTerminator(org.knime.core.node.workflow.LoopStartNodeTerminator) File(java.io.File) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) ExecutionContext(org.knime.core.node.ExecutionContext) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeLogger(org.knime.core.node.NodeLogger) Optional(java.util.Optional) Function(java.util.function.Function) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) LoopStartNodeTerminator(org.knime.core.node.workflow.LoopStartNodeTerminator)

Example 79 with ExecutionContext

use of org.knime.core.node.ExecutionContext 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 80 with ExecutionContext

use of org.knime.core.node.ExecutionContext in project knime-core by knime.

the class NaiveBayesPredictorNodeModel2 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 {
            PMMLPortObject pmmlPortObj = (PMMLPortObject) ((PortObjectInput) inputs[MODEL_IN_PORT]).getPortObject();
            DataTableSpec inSpec = (DataTableSpec) inSpecs[DATA_IN_PORT];
            StreamableFunction fct = createColumnRearranger(pmmlPortObj, inSpec).createStreamableFunction(DATA_IN_PORT, 0);
            fct.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) 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)

Aggregations

ExecutionContext (org.knime.core.node.ExecutionContext)107 DataTableSpec (org.knime.core.data.DataTableSpec)61 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)57 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)45 BufferedDataTable (org.knime.core.node.BufferedDataTable)44 DataRow (org.knime.core.data.DataRow)35 RowInput (org.knime.core.node.streamable.RowInput)26 RowOutput (org.knime.core.node.streamable.RowOutput)24 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)23 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)20 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)20 DataColumnSpec (org.knime.core.data.DataColumnSpec)19 DataCell (org.knime.core.data.DataCell)18 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)15 NodeModel (org.knime.core.node.NodeModel)14 PortObject (org.knime.core.node.port.PortObject)14 RowKey (org.knime.core.data.RowKey)13 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)13 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)13 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)12