Search in sources :

Example 11 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class BigGroupByTable method createTableRows.

/**
 * Creates and adds the result rows for the members of a data chunk to the
 * given data container. It also handles the row key mapping if hilite
 * translation is enabled.
 *
 * @param dc the {@link DataContainer} to use
 * @param chunkMembers the members of the current data chunk
 * @param groupCounter the number of groups that have been created
 * so fare
 */
private void createTableRows(final BufferedDataContainer dc, final Map<GroupKey, Pair<ColumnAggregator[], Set<RowKey>>> chunkMembers, final MutableInteger groupCounter) {
    if (chunkMembers == null || chunkMembers.isEmpty()) {
        return;
    }
    for (final Entry<GroupKey, Pair<ColumnAggregator[], Set<RowKey>>> e : chunkMembers.entrySet()) {
        final DataCell[] groupVals = e.getKey().getGroupVals();
        final ColumnAggregator[] colAggregators = e.getValue().getFirst();
        final RowKey rowKey = RowKey.createRowKey(groupCounter.intValue());
        groupCounter.inc();
        final DataCell[] rowVals = new DataCell[groupVals.length + colAggregators.length];
        // add the group values first
        int valIdx = 0;
        for (final DataCell groupCell : groupVals) {
            rowVals[valIdx++] = groupCell;
        }
        // add the aggregation values
        for (final ColumnAggregator colAggr : colAggregators) {
            final AggregationOperator operator = colAggr.getOperator(getGlobalSettings());
            rowVals[valIdx++] = operator.getResult();
            if (operator.isSkipped()) {
                // add skipped groups and the column that causes the
                // skipping into the skipped groups map
                addSkippedGroup(colAggr.getOriginalColName(), operator.getSkipMessage(), groupVals);
            }
            m_missingValuesMap.get(colAggr.getOriginalColName()).add(operator.getMissingValuesCount());
        }
        final DataRow newRow = new DefaultRow(rowKey, rowVals);
        dc.addRowToTable(newRow);
        if (isEnableHilite()) {
            final Set<RowKey> oldKeys = e.getValue().getSecond();
            addHiliteMapping(rowKey, oldKeys);
        }
    }
}
Also used : AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) Pair(org.knime.core.util.Pair)

Example 12 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class AggregationCellFactory method getColumnSpecs.

/**
 * {@inheritDoc}
 */
@Override
public DataColumnSpec[] getColumnSpecs() {
    final DataColumnSpec[] specs = new DataColumnSpec[m_operators.length];
    for (int i = 0; i < m_operators.length; i++) {
        final AggregationOperator operator = m_operators[i];
        specs[i] = operator.createColumnSpec(m_colNames[i], m_dummyOrigSpec);
    }
    return specs;
}
Also used : NamedAggregationOperator(org.knime.base.data.aggregation.NamedAggregationOperator) AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Example 13 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class MovingAggregationTableFactory method getCumulativeTable.

private BufferedDataTable getCumulativeTable(final ExecutionContext exec, final BufferedDataTable table, final BufferedDataContainer dc) throws CanceledExecutionException {
    final int rowCount = table.getRowCount();
    int rowIdx = 0;
    for (final DataRow row : table) {
        exec.setProgress(rowIdx / (double) rowCount, "Processing row " + rowIdx + " of " + rowCount);
        exec.checkCanceled();
        final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
        int idx = 0;
        // handle the retained columns
        for (final int colIdx : m_cols2KeepIdxs) {
            cells[idx++] = row.getCell(colIdx);
        }
        for (int i = 0, length = m_ops.length; i < length; i++) {
            final int colIdx = m_aggrColIdxs[i];
            final AggregationOperator op = m_ops[i];
            op.compute(row, colIdx);
            cells[idx++] = op.getResult();
        }
        dc.addRowToTable(new DefaultRow(row.getKey(), cells));
    }
    dc.close();
    return dc.getTable();
}
Also used : AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow)

Aggregations

AggregationOperator (org.knime.base.data.aggregation.AggregationOperator)13 DataCell (org.knime.core.data.DataCell)7 DataRow (org.knime.core.data.DataRow)6 DefaultRow (org.knime.core.data.def.DefaultRow)6 LinkedList (java.util.LinkedList)3 ColumnAggregator (org.knime.base.data.aggregation.ColumnAggregator)2 NamedAggregationOperator (org.knime.base.data.aggregation.NamedAggregationOperator)2 RowKey (org.knime.core.data.RowKey)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)2 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 AggregationMethod (org.knime.base.data.aggregation.AggregationMethod)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1 Pair (org.knime.core.util.Pair)1