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