use of org.knime.base.node.preproc.filter.row.RowFilterIterator in project knime-core by knime.
the class SamplingNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable in = inData[0];
// he following line does not need the exec monitor. It's
// only used when the table is traversed in order to count the rows.
// This is done only if "in" does not support getRowCount().
// But the argument in the execute method surely does!
IRowFilter filter = getSamplingRowFilter(in, exec);
BufferedDataContainer container = exec.createDataContainer(in.getDataTableSpec());
try {
int count = 0;
RowFilterIterator it = new RowFilterIterator(in, filter, exec);
while (it.hasNext()) {
DataRow row = it.next();
exec.setMessage("Adding row " + count + " (\"" + row.getKey() + "\")");
count++;
container.addRowToTable(row);
}
} catch (RowFilterIterator.RuntimeCanceledExecutionException rce) {
throw rce.getCause();
} finally {
container.close();
}
BufferedDataTable out = container.getTable();
if (filter instanceof StratifiedSamplingRowFilter) {
int classCount = ((StratifiedSamplingRowFilter) filter).getClassCount();
if (classCount > out.getRowCount()) {
setWarningMessage("Class column contains more classes (" + classCount + ") than sampled rows (" + out.getRowCount() + ")");
}
}
return new BufferedDataTable[] { out };
}
Aggregations