Search in sources :

Example 1 with RowFilterIterator

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 };
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowFilterIterator(org.knime.base.node.preproc.filter.row.RowFilterIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable) IRowFilter(org.knime.base.node.preproc.filter.row.rowfilter.IRowFilter) DataRow(org.knime.core.data.DataRow)

Aggregations

RowFilterIterator (org.knime.base.node.preproc.filter.row.RowFilterIterator)1 IRowFilter (org.knime.base.node.preproc.filter.row.rowfilter.IRowFilter)1 DataRow (org.knime.core.data.DataRow)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1