use of org.knime.core.data.container.RowAppender in project knime-core by knime.
the class RuleEngineFilter2PortsNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable ruleTable = inData[RuleEngine2PortsNodeModel.RULE_PORT];
BufferedDataTable dataTable = inData[RuleEngine2PortsNodeModel.DATA_PORT];
// m_rulesList.clear();
// m_rulesList.addAll(RuleEngineVariable2PortsNodeModel.rules(ruleTable, m_settings, RuleNodeSettings.RuleFilter));
// final List<Rule> rules = parseRules(dataTable.getDataTableSpec(), RuleNodeSettings.RuleFilter);
final BufferedDataContainer first = exec.createDataContainer(dataTable.getDataTableSpec(), true);
final int nrOutPorts = getNrOutPorts();
final RowAppender second = nrOutPorts > 1 ? exec.createDataContainer(dataTable.getDataTableSpec(), true) : new RowAppender() {
@Override
public void addRowToTable(final DataRow row) {
// do nothing
}
};
// final RowAppender[] containers = new RowAppender[]{first, second};
// final int matchIndex = m_includeOnMatch ? 0 : 1;
// final int otherIndex = 1 - matchIndex;
//
final BufferedDataTable[] ret = new BufferedDataTable[nrOutPorts];
// try {
// final MutableLong rowIdx = new MutableLong();
// final long rows = inData[DATA_PORT].size();
// final VariableProvider provider = new VariableProvider() {
// @Override
// public Object readVariable(final String name, final Class<?> type) {
// return RuleEngineFilter2PortsNodeModel.this.readVariable(name, type);
// }
//
// @Override
// @Deprecated
// public int getRowCount() {
// throw new UnsupportedOperationException();
// }
//
// @Override
// public long getRowCountLong() {
// return rows;
// }
//
// @Override
// @Deprecated
// public int getRowIndex() {
// throw new UnsupportedOperationException();
// }
//
// @Override
// public long getRowIndexLong() {
// return rowIdx.longValue();
// }
// };
// for (DataRow row : inData[DATA_PORT]) {
// rowIdx.increment();
// exec.setProgress(rowIdx.longValue() / (double)rows, "Adding row " + rowIdx.longValue() + " of " + rows);
// exec.checkCanceled();
// boolean wasMatch = false;
// for (final Rule r : rules) {
// if (r.getCondition().matches(row, provider).getOutcome() == MatchState.matchedAndStop) {
// // r.getSideEffect().perform(row, provider);
// DataValue value = r.getOutcome().getComputedResult(row, provider);
// if (value instanceof BooleanValue) {
// final BooleanValue bv = (BooleanValue)value;
// containers[bv.getBooleanValue() ? matchIndex : otherIndex].addRowToTable(row);
// } else {
// containers[matchIndex].addRowToTable(row);
// }
// wasMatch = true;
// break;
// }
// }
// if (!wasMatch) {
// containers[otherIndex].addRowToTable(row);
// }
// }
// } finally {
// first.close();
// ret[0] = first.getTable();
// if (second instanceof BufferedDataContainer) {
// BufferedDataContainer container = (BufferedDataContainer)second;
// container.close();
// ret[1] = container.getTable();
// }
// }
final PortOutput[] outputs = new PortOutput[] { new BufferedDataTableRowOutput(first), new RowAppenderRowOutput(second) };
final StreamableOperator streamableOperator = createStreamableOperator(new PartitionInfo(0, 1), new DataTableSpec[] { inData[0].getSpec(), inData[1].getSpec() });
final PortInput[] inputs = new PortInput[] { new DataTableRowInput(dataTable), new DataTableRowInput(ruleTable) };
final SimpleStreamableOperatorInternals internals = new SimpleStreamableOperatorInternals();
internals.getConfig().addLong(CFG_ROW_COUNT, dataTable.size());
streamableOperator.loadInternals(internals);
streamableOperator.runFinal(inputs, outputs, exec);
ret[0] = first.getTable();
if (ret.length > 1) {
ret[1] = ((BufferedDataContainer) second).getTable();
}
return ret;
}
Aggregations