Search in sources :

Example 6 with TableFilter

use of org.knime.core.data.container.filter.TableFilter in project knime-core by knime.

the class JoinedTable method checkRowKeysMatch.

private static void checkRowKeysMatch(final BufferedDataTable left, final BufferedDataTable right, final ExecutionMonitor prog, final long cnt) throws CanceledExecutionException {
    final TableFilter filter = TableFilter.materializeCols();
    // check if rows come in same order
    try (CloseableRowIterator leftIt = left.filter(filter).iterator();
        CloseableRowIterator rightIt = right.filter(filter).iterator()) {
        long rowIndex = 0;
        while (leftIt.hasNext()) {
            RowKey leftKey = leftIt.next().getKey();
            RowKey rightKey = rightIt.next().getKey();
            if (!leftKey.equals(rightKey)) {
                throw new IllegalArgumentException("Tables contain non-matching rows or are sorted differently, keys in row " + rowIndex + " do not match: \"" + leftKey + "\" vs. \"" + rightKey + "\"");
            }
            prog.checkCanceled();
            final long finalRowIndex = rowIndex;
            prog.setProgress(rowIndex / (double) cnt, () -> "\"" + leftKey + "\" (" + finalRowIndex + "/" + cnt + ")");
            rowIndex++;
        }
    }
}
Also used : TableFilter(org.knime.core.data.container.filter.TableFilter) RowKey(org.knime.core.data.RowKey)

Aggregations

TableFilter (org.knime.core.data.container.filter.TableFilter)6 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 ExecutionContext (org.knime.core.node.ExecutionContext)3 Test (org.junit.Test)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 RowKey (org.knime.core.data.RowKey)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Vector (java.util.Vector)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Supplier (java.util.function.Supplier)1 IntStream (java.util.stream.IntStream)1