Search in sources :

Example 76 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class RearrangeColumnsTable method calcNewColsSynchronously.

/**
 * Processes input sequentially in the caller thread.
 */
private static void calcNewColsSynchronously(final BufferedDataTable table, final ExecutionMonitor subProgress, final NewColumnsProducerMapping newColsProducerMapping, final DataContainer container) throws CanceledExecutionException {
    long finalRowCount = table.size();
    Set<CellFactory> newColsFactories = newColsProducerMapping.getUniqueCellFactoryMap().keySet();
    final int factoryCount = newColsFactories.size();
    int r = 0;
    CellFactory facForProgress = factoryCount > 0 ? newColsFactories.iterator().next() : null;
    for (RowIterator it = table.iterator(); it.hasNext(); r++) {
        DataRow row = it.next();
        DataRow append = calcNewCellsForRow(row, newColsProducerMapping);
        container.addRowToTable(append);
        if (facForProgress == null) {
            // no factory added means at least one columns gets type converted.
            assert !newColsProducerMapping.getConverterToIndexMap().isEmpty();
        } else {
            facForProgress.setProgress(r + 1, finalRowCount, row.getKey(), subProgress);
        }
        subProgress.checkCanceled();
    }
}
Also used : RowIterator(org.knime.core.data.RowIterator) DataRow(org.knime.core.data.DataRow)

Example 77 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class AbstractColumnTableSorter method sort.

/**
 * @param dataTable the table to sort
 * @param exec the execution context
 * @param resultListener the result listener
 * @throws CanceledExecutionException if the user cancels the execution
 */
void sort(final DataTable dataTable, final ExecutionMonitor exec, final SortingConsumer resultListener) throws CanceledExecutionException {
    if (m_sortDescriptions.length <= 0) {
        for (DataRow r : dataTable) {
            resultListener.consume(new DefaultRow(r.getKey(), new DataCell[0]));
        }
    } else {
        clearBuffer();
        sortOnDisk(dataTable, exec, resultListener);
    }
}
Also used : DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) DataRow(org.knime.core.data.DataRow)

Example 78 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class AbstractColumnTableSorter method fillBuffer.

/**
 * @param m_buffer
 * @param iterator
 * @param checkMemory
 * @param exec
 * @throws CanceledExecutionException
 */
private long fillBuffer(final RowIterator iterator, final ExecutionMonitor readExec) throws CanceledExecutionException {
    long count = 0;
    while (iterator.hasNext()) {
        count += 1;
        readExec.checkCanceled();
        DataRow r = iterator.next();
        for (Entry<SortingDescription, List<DataRow>> descr : m_buffer.entrySet()) {
            descr.getValue().add(descr.getKey().createSubRow(r));
        }
        // read at least two rows, otherwise we won't make any progress
        if ((count >= 2) && m_memActionIndicator.lowMemoryActionRequired()) {
            break;
        }
    }
    return count;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) DataRow(org.knime.core.data.DataRow)

Example 79 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class AbstractColumnTableSorter method toSortDescriptions.

private static SortingDescription[] toSortDescriptions(final DataTableSpec dataTableSpec, final String[] toSort) throws InvalidSettingsException {
    checkArgument(!ArrayUtils.contains(toSort, null), "Null values are not permitted.");
    SortingDescription[] toReturn = new SortingDescription[toSort.length];
    int index = 0;
    for (String so : toSort) {
        DataColumnSpec columnSpec = checkSettingNotNull(dataTableSpec.getColumnSpec(so), "Column: '%s' does not exist in input table.", so);
        final DataValueComparator comparator = columnSpec.getType().getComparator();
        toReturn[index++] = new SortingDescription(so) {

            @Override
            public int compare(final DataRow o1, final DataRow o2) {
                return comparator.compare(o1.getCell(0), o2.getCell(0));
            }
        };
    }
    return toReturn;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataValueComparator(org.knime.core.data.DataValueComparator) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) DataRow(org.knime.core.data.DataRow)

Example 80 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class TableContentModel method getValueAt.

// getRowCount()
/**
 * Get the DataCell at a specific location. If the requested row is in the
 * cache, it will be returned. Otherwise the ring buffer is updated
 * (iterator pushed forward or reset) until the row is in the cache.
 *
 * @param row the row index
 * @param column the column index
 * @return the <code>DataCell</code> in the underlying
 *         <code>DataTable</code> at position [<code>row, column</code>]
 * @throws IndexOutOfBoundsException if either argument violates its range
 */
@Override
public DataCell getValueAt(final int row, final int column) {
    boundColumn(column);
    DataRow result = getRow(row);
    return result.getCell(column);
}
Also used : DataRow(org.knime.core.data.DataRow)

Aggregations

DataRow (org.knime.core.data.DataRow)482 DataCell (org.knime.core.data.DataCell)268 DataTableSpec (org.knime.core.data.DataTableSpec)159 BufferedDataTable (org.knime.core.node.BufferedDataTable)125 DataColumnSpec (org.knime.core.data.DataColumnSpec)109 RowKey (org.knime.core.data.RowKey)88 DefaultRow (org.knime.core.data.def.DefaultRow)88 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)80 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)76 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)73 DoubleValue (org.knime.core.data.DoubleValue)72 ArrayList (java.util.ArrayList)65 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)65 RowIterator (org.knime.core.data.RowIterator)62 DataType (org.knime.core.data.DataType)61 DoubleCell (org.knime.core.data.def.DoubleCell)57 StringCell (org.knime.core.data.def.StringCell)53 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)48 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)44 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)43