Search in sources :

Example 1 with GlobalSettings

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

the class MovingAggregationNodeModel method createTableFactory.

private MovingAggregationTableFactory createTableFactory(final FileStoreFactory fsf, final DataTableSpec spec) {
    final GlobalSettings globalSettings = new GlobalSettings(fsf, Collections.<String>emptyList(), m_maxUniqueVals.getIntValue(), m_valueDelimiter.getJavaUnescapedStringValue(), spec, 0);
    final ColumnNamePolicy colNamePolicy = ColumnNamePolicy.getPolicy4Label(m_columnNamePolicy.getStringValue());
    final MovingAggregationTableFactory tableFactory = new MovingAggregationTableFactory(spec, globalSettings, colNamePolicy, m_columnAggregators2Use, m_cumulativeComputing.getBooleanValue(), WindowType.getType(m_windowType.getStringValue()), m_winLength.getIntValue(), m_handleMissings.getBooleanValue(), m_removeAggregationCols.getBooleanValue(), m_removeRetainedCols.getBooleanValue());
    return tableFactory;
}
Also used : ColumnNamePolicy(org.knime.base.node.preproc.groupby.ColumnNamePolicy) GlobalSettings(org.knime.base.data.aggregation.GlobalSettings)

Example 2 with GlobalSettings

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

the class CrosstabNodeModel method createGroupByTable.

/**
 * Create group-by table.
 * @param exec execution context
 * @param table input table to group
 * @param groupByCols column selected for group-by operation
 * @return table with group and aggregation columns
 * @throws CanceledExecutionException if the group-by table generation was
 *         canceled externally
 */
private final GroupByTable createGroupByTable(final ExecutionContext exec, final BufferedDataTable table, final List<String> groupByCols) throws CanceledExecutionException {
    final int maxUniqueVals = Integer.MAX_VALUE;
    final boolean enableHilite = m_settings.getEnableHiliting();
    final boolean retainOrder = false;
    final ColumnNamePolicy colNamePolicy = ColumnNamePolicy.AGGREGATION_METHOD_COLUMN_NAME;
    final GlobalSettings globalSettings = GlobalSettings.builder().setFileStoreFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec)).setGroupColNames(groupByCols).setMaxUniqueValues(maxUniqueVals).setValueDelimiter(GlobalSettings.STANDARD_DELIMITER).setDataTableSpec(table.getDataTableSpec()).setNoOfRows(table.size()).setAggregationContext(AggregationContext.ROW_AGGREGATION).build();
    ColumnAggregator collAggregator = null;
    if (null != m_settings.getWeightColumn()) {
        final String weightColumn = m_settings.getWeightColumn();
        // the column aggregator for the weighting column
        final boolean inclMissing = false;
        final DataColumnSpec originalColSpec = table.getDataTableSpec().getColumnSpec(weightColumn);
        final OperatorColumnSettings opColSettings = new OperatorColumnSettings(inclMissing, originalColSpec);
        collAggregator = new ColumnAggregator(originalColSpec, new NonNegativeSumOperator(globalSettings, opColSettings), inclMissing);
    } else {
        // use any column, does not matter as long as it exists and
        // include missing is true;
        final boolean inclMissing = true;
        final DataColumnSpec originalColSpec = table.getDataTableSpec().getColumnSpec(groupByCols.get(0));
        final OperatorColumnSettings opColSettings = new OperatorColumnSettings(inclMissing, originalColSpec);
        collAggregator = new ColumnAggregator(originalColSpec, new CountOperator(globalSettings, opColSettings), inclMissing);
    }
    final GroupByTable resultTable = new BigGroupByTable(exec, table, groupByCols, new ColumnAggregator[] { collAggregator }, globalSettings, enableHilite, colNamePolicy, retainOrder);
    if (enableHilite) {
        setHiliteMapping(new DefaultHiLiteMapper(resultTable.getHiliteMapping()));
    }
    // check for skipped columns
    final String warningMsg = resultTable.getSkippedGroupsMessage(3, 3);
    if (warningMsg != null) {
        setWarningMessage(warningMsg);
    }
    return resultTable;
}
Also used : OperatorColumnSettings(org.knime.base.data.aggregation.OperatorColumnSettings) GlobalSettings(org.knime.base.data.aggregation.GlobalSettings) ColumnNamePolicy(org.knime.base.node.preproc.groupby.ColumnNamePolicy) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) BigGroupByTable(org.knime.base.node.preproc.groupby.BigGroupByTable) GroupByTable(org.knime.base.node.preproc.groupby.GroupByTable) BigGroupByTable(org.knime.base.node.preproc.groupby.BigGroupByTable) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) CountOperator(org.knime.base.data.aggregation.general.CountOperator)

Example 3 with GlobalSettings

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

the class GroupByNodeModel method createGroupByTable.

/**
 * Create group-by table.
 * @param exec execution context
 * @param table input table to group
 * @param groupByCols column selected for group-by operation
 * @param inMemory keep data in memory
 * @param sortInMemory does sorting in memory
 * @param retainOrder reconstructs original data order
 * @param aggregators column aggregation to use
 * @return table with group and aggregation columns
 * @throws CanceledExecutionException if the group-by table generation was
 *         canceled externally
 * @deprecated sortInMemory is no longer required
 * @see #createGroupByTable(ExecutionContext, BufferedDataTable, List,
 * boolean, boolean, List)
 */
@Deprecated
protected final GroupByTable createGroupByTable(final ExecutionContext exec, final BufferedDataTable table, final List<String> groupByCols, final boolean inMemory, final boolean sortInMemory, final boolean retainOrder, final List<ColumnAggregator> aggregators) throws CanceledExecutionException {
    final int maxUniqueVals = m_maxUniqueValues.getIntValue();
    final boolean enableHilite = m_enableHilite.getBooleanValue();
    final ColumnNamePolicy colNamePolicy = ColumnNamePolicy.getPolicy4Label(m_columnNamePolicy.getStringValue());
    final GlobalSettings globalSettings = createGlobalSettings(exec, table, groupByCols, maxUniqueVals);
    // reset all aggregators in order to use enforce operator creation
    for (final ColumnAggregator colAggr : aggregators) {
        colAggr.reset();
    }
    final GroupByTable resultTable;
    if (inMemory || groupByCols.isEmpty()) {
        resultTable = new MemoryGroupByTable(exec, table, groupByCols, aggregators.toArray(new ColumnAggregator[0]), globalSettings, enableHilite, colNamePolicy, retainOrder);
    } else {
        resultTable = new BigGroupByTable(exec, table, groupByCols, aggregators.toArray(new ColumnAggregator[0]), globalSettings, enableHilite, colNamePolicy, retainOrder);
    }
    if (m_enableHilite.getBooleanValue()) {
        setHiliteMapping(new DefaultHiLiteMapper(resultTable.getHiliteMapping()));
    }
    // check for skipped columns
    final String warningMsg = resultTable.getSkippedGroupsMessage(3, 3);
    if (warningMsg != null) {
        setWarningMessage(warningMsg);
        LOGGER.info(resultTable.getSkippedGroupsMessage(Integer.MAX_VALUE, Integer.MAX_VALUE));
    }
    return resultTable;
}
Also used : ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) GlobalSettings(org.knime.base.data.aggregation.GlobalSettings) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper)

Example 4 with GlobalSettings

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

the class ColumnAggregatorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable table = inData[0];
    final DataTableSpec origSpec = table.getSpec();
    final FilterResult filterResult = m_aggregationCols.applyTo(origSpec);
    final List<String> selectedCols = Arrays.asList(filterResult.getIncludes());
    final GlobalSettings globalSettings = GlobalSettings.builder().setFileStoreFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec)).setGroupColNames(selectedCols).setMaxUniqueValues(m_maxUniqueValues.getIntValue()).setValueDelimiter(getDefaultValueDelimiter()).setDataTableSpec(origSpec).setNoOfRows(table.size()).setAggregationContext(AggregationContext.COLUMN_AGGREGATION).build();
    final AggregationCellFactory cellFactory = new AggregationCellFactory(origSpec, selectedCols, globalSettings, m_methods);
    final ColumnRearranger cr = createRearranger(origSpec, cellFactory);
    final BufferedDataTable out = exec.createColumnRearrangeTable(table, cr, exec);
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) GlobalSettings(org.knime.base.data.aggregation.GlobalSettings) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 5 with GlobalSettings

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

the class ColumnAggregatorNodeModel method createStreamableOperator.

/* ================= STREAMING ================= */
/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final DataTableSpec origSpec = (DataTableSpec) inSpecs[0];
            final FilterResult filterResult = m_aggregationCols.applyTo(origSpec);
            final List<String> selectedCols = Arrays.asList(filterResult.getIncludes());
            final GlobalSettings globalSettings = GlobalSettings.builder().setFileStoreFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec)).setGroupColNames(selectedCols).setMaxUniqueValues(m_maxUniqueValues.getIntValue()).setValueDelimiter(getDefaultValueDelimiter()).setDataTableSpec(origSpec).setNoOfRows(-1).setAggregationContext(AggregationContext.COLUMN_AGGREGATION).build();
            final AggregationCellFactory cellFactory = new AggregationCellFactory(origSpec, selectedCols, globalSettings, m_methods);
            final ColumnRearranger cr = createRearranger(origSpec, cellFactory);
            cr.createStreamableFunction().runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) GlobalSettings(org.knime.base.data.aggregation.GlobalSettings) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

GlobalSettings (org.knime.base.data.aggregation.GlobalSettings)6 ColumnAggregator (org.knime.base.data.aggregation.ColumnAggregator)3 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3 BigGroupByTable (org.knime.base.node.preproc.groupby.BigGroupByTable)2 ColumnNamePolicy (org.knime.base.node.preproc.groupby.ColumnNamePolicy)2 GroupByTable (org.knime.base.node.preproc.groupby.GroupByTable)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)2 FilterResult (org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)2 OperatorColumnSettings (org.knime.base.data.aggregation.OperatorColumnSettings)1 CountOperator (org.knime.base.data.aggregation.general.CountOperator)1 MemoryGroupByTable (org.knime.base.node.preproc.groupby.MemoryGroupByTable)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 ExecutionContext (org.knime.core.node.ExecutionContext)1 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)1 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)1