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);
}
};
}
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];
}
}
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];
}
}
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));
}
};
}
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);
}
};
}
Aggregations