Search in sources :

Example 6 with NamedAggregationOperator

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

the class ColumnAggregationPanel method initialize.

/**
 * Initializes the panel.
 * @param type the {@link DataType} the methods should support
 * @param methods the {@link List} of {@link NamedAggregationOperator}s
 * that are initially used
 * @param spec input {@link DataTableSpec}
 * @since 2.7
 */
public void initialize(final DataType type, final List<NamedAggregationOperator> methods, final DataTableSpec spec) {
    m_type = type;
    // update the compatible methods list
    final List<NamedAggregationOperator> methods2Use = new ArrayList<>(methods.size());
    if (m_type != null) {
        // remove selected methods that are not compatible with the new type
        for (final NamedAggregationOperator method : methods) {
            if (method.isCompatible(m_type)) {
                methods2Use.add(method);
            }
        }
        super.initialize(AggregationMethods.getCompatibleMethods(m_type, true), methods2Use, spec);
    }
}
Also used : NamedAggregationOperator(org.knime.base.data.aggregation.NamedAggregationOperator) ArrayList(java.util.ArrayList)

Example 7 with NamedAggregationOperator

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

the class ColumnAggregatorNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_aggregationCols.validateSettings(settings);
    m_removeRetainedCols.validateSettings(settings);
    m_removeAggregationCols.validateSettings(settings);
    m_valueDelimiter.validateSettings(settings);
    m_maxUniqueValues.validateSettings(settings);
    if (!settings.containsKey(CFG_AGGREGATION_METHODS)) {
        throw new InvalidSettingsException("Methods configuration not found");
    }
    // check for duplicate column names
    final NodeSettingsRO subSettings = settings.getNodeSettings(ColumnAggregatorNodeModel.CFG_AGGREGATION_METHODS);
    final List<NamedAggregationOperator> methods = NamedAggregationOperator.loadOperators(subSettings);
    if (methods.isEmpty()) {
        throw new InvalidSettingsException("Please select at least one aggregation method");
    }
    final Map<String, Integer> colNames = new HashMap<>(methods.size());
    int colIdx = 1;
    for (final NamedAggregationOperator method : methods) {
        final Integer oldIdx = colNames.put(method.getName(), Integer.valueOf(colIdx));
        if (oldIdx != null) {
            throw new InvalidSettingsException("Duplicate column name '" + method.getName() + "' found in row " + oldIdx + " and " + colIdx);
        }
        colIdx++;
    }
    // validate the sub settings of all operators that require additional settings
    NamedAggregationOperator.validateSettings(subSettings, methods);
}
Also used : SettingsModelInteger(org.knime.core.node.defaultnodesettings.SettingsModelInteger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) HashMap(java.util.HashMap) NamedAggregationOperator(org.knime.base.data.aggregation.NamedAggregationOperator) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

NamedAggregationOperator (org.knime.base.data.aggregation.NamedAggregationOperator)7 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 SettingsModelInteger (org.knime.core.node.defaultnodesettings.SettingsModelInteger)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1