Search in sources :

Example 16 with ExecutionContext

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

the class MissingValueHandling3Table method createMissingValueHandlingTable.

/**
 * Does missing value handling to the argument table given the col settings in an array and also reports progress.
 *
 * @param table the table to do missing value handling on
 * @param colSettings the settings
 * @param exec for progress/cancel and to create the buffered data table
 * @param warningBuffer To which potential warning messages are added.
 * @return a cache table, cleaned up
 * @throws CanceledExecutionException if canceled
 * @since 2.10
 */
public static BufferedDataTable createMissingValueHandlingTable(final BufferedDataTable table, final MissingValueHandling2ColSetting[] colSettings, final ExecutionContext exec, final StringBuilder warningBuffer) throws CanceledExecutionException {
    MissingValueHandling2ColSetting[] colSetting;
    try {
        colSetting = getColSetting(table.getDataTableSpec(), colSettings, false, warningBuffer);
    } catch (InvalidSettingsException ise) {
        LOGGER.coding("getColSetting method is not supposed to throw an exception, ignoring settings", ise);
        DataTableSpec s = table.getDataTableSpec();
        colSetting = new MissingValueHandling2ColSetting[s.getNumColumns()];
        for (int i = 0; i < s.getNumColumns(); i++) {
            colSetting[i] = new MissingValueHandling2ColSetting(s.getColumnSpec(i));
            colSetting[i].setMethod(MissingValueHandling2ColSetting.METHOD_NO_HANDLING);
        }
    }
    boolean needStatistics = false;
    final Set<Integer> mostFrequentColumns = new HashSet<Integer>();
    for (int i = 0; i < colSetting.length; i++) {
        MissingValueHandling2ColSetting c = colSetting[i];
        switch(c.getMethod()) {
            case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
                mostFrequentColumns.add(i);
            case MissingValueHandling2ColSetting.METHOD_MAX:
            case MissingValueHandling2ColSetting.METHOD_MIN:
            case MissingValueHandling2ColSetting.METHOD_MEAN:
                needStatistics = true;
                break;
            default:
        }
    }
    MyStatisticsTable myT;
    ExecutionMonitor e;
    if (needStatistics) {
        // for creating statistics table
        ExecutionContext subExec = exec.createSubExecutionContext(0.5);
        myT = new MyStatisticsTable(table, subExec) {

            // do not try to get this Iterable in the constructor, it will not work, as long as
            // Statistics3Table does the statistical computation in the constructor.
            @Override
            protected Iterable<Integer> getMostFrequentColumns() {
                return mostFrequentColumns;
            }
        };
        if (myT.m_warningMessage != null) {
            if (warningBuffer.length() > 0) {
                warningBuffer.append('\n');
            }
            warningBuffer.append(myT.m_warningMessage);
        }
        // for the iterator
        e = exec.createSubProgress(0.5);
    } else {
        myT = null;
        e = exec;
    }
    MissingValueHandling3Table mvht = new MissingValueHandling3Table(table, myT, colSetting);
    BufferedDataContainer container = exec.createDataContainer(mvht.getDataTableSpec());
    e.setMessage("Adding rows...");
    int count = 0;
    try {
        MissingValueHandling3TableIterator it = new MissingValueHandling3TableIterator(mvht, e);
        while (it.hasNext()) {
            DataRow next;
            next = it.next();
            e.setMessage("Adding row " + (count + 1) + " (\"" + next.getKey() + "\")");
            container.addRowToTable(next);
            count++;
        }
    } catch (MissingValueHandling3TableIterator.RuntimeCanceledExecutionException rcee) {
        throw rcee.getCause();
    } finally {
        container.close();
    }
    return container.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataRow(org.knime.core.data.DataRow) ExecutionContext(org.knime.core.node.ExecutionContext) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 17 with ExecutionContext

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

the class TreeEnsembleRegressionPredictorNodeModel 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 {
            TreeEnsembleModelPortObject model = (TreeEnsembleModelPortObject) ((PortObjectInput) inputs[0]).getPortObject();
            TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
            DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
            final TreeEnsemblePredictor pred = new TreeEnsemblePredictor(modelSpec, model, dataSpec, m_configuration);
            ColumnRearranger rearranger = pred.getPredictionRearranger();
            StreamableFunction func = rearranger.createStreamableFunction(1, 0);
            func.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble.node.predictor.TreeEnsemblePredictor) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 18 with ExecutionContext

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

the class JoinerJoinAnyTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    NodeFactory<NodeModel> dummyFactory = (NodeFactory) new VirtualParallelizedChunkPortObjectInNodeFactory(new PortType[0]);
    m_exec = new ExecutionContext(new DefaultNodeProgressMonitor(), new Node(dummyFactory), SingleNodeContainer.MemoryPolicy.CacheOnDisc, new HashMap<Integer, ContainerTable>());
}
Also used : NodeModel(org.knime.core.node.NodeModel) ExecutionContext(org.knime.core.node.ExecutionContext) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) NodeFactory(org.knime.core.node.NodeFactory) HashMap(java.util.HashMap) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) Node(org.knime.core.node.Node) PortType(org.knime.core.node.port.PortType) Before(org.junit.Before)

Example 19 with ExecutionContext

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

the class AbstractBlobsInWorkflowTest method setUp.

/**
 * {@inheritDoc}
 */
@Override
protected void setUp() throws Exception {
    m_wfmDir = FileUtil.createTempDir(getClass().getSimpleName());
    WorkflowCreationHelper creationHelper = new WorkflowCreationHelper();
    creationHelper.setWorkflowContext(new WorkflowContext.Factory(m_wfmDir).createContext());
    WorkflowManager m = WorkflowManager.ROOT.createAndAddProject("Blob test", creationHelper);
    RuntimeNodeModel createModel = new RuntimeNodeModel(0, 1) {

        /**
         * {@inheritDoc}
         */
        @Override
        protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
            return new BufferedDataTable[] { createBDT(exec) };
        }
    };
    NodeID createID = m.createAndAddNode(new RuntimeNodeFactory(createModel));
    // add a sequence of cache nodes
    NodeID[] cacheIDs = new NodeID[10];
    CacheNodeFactory cacheNodeFactory = new CacheNodeFactory();
    for (int i = 0; i < cacheIDs.length; i++) {
        cacheIDs[i] = m.createAndAddNode(cacheNodeFactory);
        if (i == 0) {
            m.addConnection(createID, 1, cacheIDs[i], 1);
        } else {
            m.addConnection(cacheIDs[i - 1], 1, cacheIDs[i], 1);
        }
    }
    final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
    RuntimeNodeModel checkModel = new RuntimeNodeModel(1, 0) {

        /**
         * {@inheritDoc}
         */
        @Override
        protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
            try {
                new DataTableDiffer().compare(inData[0], createBDT(exec));
            } catch (TestEvaluationException tee) {
                failure.set(tee);
                throw tee;
            }
            return new BufferedDataTable[] {};
        }
    };
    NodeID checkID = m.createAndAddNode(new RuntimeNodeFactory(checkModel));
    m.addConnection(cacheIDs[cacheIDs.length - 1], 1, checkID, 1);
    m_flow = m;
    m.executeAllAndWaitUntilDone();
    assertNull(failure.get());
    assertTrue(m.getNodeContainerState().isExecuted());
}
Also used : CacheNodeFactory(org.knime.base.node.util.cache.CacheNodeFactory) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) CacheNodeFactory(org.knime.base.node.util.cache.CacheNodeFactory) RuntimeNodeFactory(org.knime.testing.node.runtime.RuntimeNodeFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestEvaluationException(org.knime.testing.node.differNode.TestEvaluationException) DataTableDiffer(org.knime.testing.node.differNode.DataTableDiffer) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) ExecutionContext(org.knime.core.node.ExecutionContext) RuntimeNodeModel(org.knime.testing.node.runtime.RuntimeNodeModel) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeID(org.knime.core.node.workflow.NodeID) RuntimeNodeFactory(org.knime.testing.node.runtime.RuntimeNodeFactory)

Example 20 with ExecutionContext

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

the class SampleDataNodeModel 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 {
            DataTableSpec[] outSpecs = configure(new DataTableSpec[2]);
            DataTableSpec dataSpec = outSpecs[0];
            DataTableSpec clusterSpec = outSpecs[1];
            RowOutput dataOut = (RowOutput) outputs[0];
            RowOutput clusterOut = (RowOutput) outputs[1];
            run(dataSpec, dataOut, clusterSpec, clusterOut, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) 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)

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