use of org.knime.base.node.preproc.joiner.Joiner2Settings in project knime-core by knime.
the class LoopEndJoinNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
boolean hasSameRowsInEachIteration = m_configuration.hasSameRowsInEachIteration();
LoopStartNode startNode = getLoopStartNode();
if (!(startNode instanceof LoopStartNodeTerminator)) {
throw new IllegalStateException("Loop end is not connected" + " to matching/corresponding loop start node. You" + " are trying to create an infinite loop!");
}
boolean continueLoop = !((LoopStartNodeTerminator) startNode).terminateLoop();
if (m_currentAppendTable == null) {
m_currentAppendTable = copy(inData[0], false, exec);
} else if (hasSameRowsInEachIteration) {
boolean isCacheNew = m_iteration % 50 == 0;
double amount = isCacheNew ? (1.0 / 3.0) : (1.0 / 2.0);
ExecutionContext copyCtx = exec.createSubExecutionContext(amount);
ExecutionContext joinCtx = exec.createSubExecutionContext(amount);
exec.setProgress("Copying input");
BufferedDataTable t = copy(inData[0], true, copyCtx);
copyCtx.setProgress(1.0);
exec.setProgress("Joining with previous input");
m_currentAppendTable = exec.createJoinedTable(m_currentAppendTable, t, joinCtx);
joinCtx.setProgress(1.0);
if (isCacheNew) {
exec.setProgress("Caching intermediate results (iteration " + m_iteration + ")");
ExecutionContext ctx = exec.createSubExecutionContext(amount);
// copy the whole table every 50 columns (avoids wrapping to much individual tables)
// In this case the whole table is copied and column names DON'T need to be made unique (bugfix 6544)
m_currentAppendTable = copy(m_currentAppendTable, m_appendIterSuffixForBackwardComp, ctx);
ctx.setProgress(1.0);
}
} else {
Joiner2Settings settings = new Joiner2Settings();
settings.setCompositionMode(CompositionMode.MatchAll);
settings.setDuplicateColumnSuffix(" (Iter #" + m_iteration + ")");
settings.setDuplicateHandling(DuplicateHandling.AppendSuffix);
settings.setEnableHiLite(false);
// joining on RowIDs, this should not generate new row IDs but
// only fill missing rows in either table
settings.setJoinMode(JoinMode.FullOuterJoin);
settings.setLeftIncludeAll(true);
settings.setRightIncludeAll(true);
// TODO to be replaced by Joiner2Settings.ROW_KEY_IDENTIFIER
// once that is public
settings.setLeftJoinColumns(new String[] { "$RowID$" });
settings.setRightJoinColumns(new String[] { "$RowID$" });
BufferedDataTable left = m_currentAppendTable;
BufferedDataTable right = copy(inData[0], true, exec.createSubExecutionContext(0.1));
Joiner joiner = new Joiner(left.getDataTableSpec(), right.getDataTableSpec(), settings);
m_currentAppendTable = joiner.computeJoinTable(left, right, exec.createSubExecutionContext(0.9));
}
m_iteration += 1;
if (continueLoop) {
super.continueLoop();
return null;
} else {
return new BufferedDataTable[] { m_currentAppendTable };
}
}
Aggregations