use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class AggregationFunctionAndRowTableCellRenderer method getTableCellRendererComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
assert (c == this);
final AggregationFunction function;
if (value instanceof AggregationFunctionRow) {
function = ((AggregationFunctionRow<?>) value).getFunction();
} else if (value instanceof AggregationFunction) {
function = (AggregationFunction) value;
} else {
function = null;
}
if (function != null) {
if (function instanceof InvalidAggregationFunction) {
// set a red border for invalid methods
setBorder(BorderFactory.createLineBorder(Color.RED));
} else {
setBorder(null);
}
setText(function.getLabel());
setToolTipText(function.getDescription());
}
return this;
}
use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class AbstractAggregationFunctionTableCellEditor method getTableCellEditorComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int rowIdx, final int column) {
if (value instanceof AggregationFunctionRow<?>) {
@SuppressWarnings("unchecked") R row = (R) value;
final DataType type = getDataType(table, row, isSelected, rowIdx, column);
final AggregationFunction selectedMethod = getSelectedAggregationMethod(table, row, isSelected, rowIdx, column);
final List<? extends AggregationFunction> compatibleMethods = getCompatibleMethods(type);
if (type != null) {
getBox().update(type, compatibleMethods, selectedMethod);
}
}
return super.getTableCellEditorComponent(table, value, isSelected, rowIdx, column);
}
use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class AggregationFunctionAndRowListCellRenderer method getListCellRendererComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getListCellRendererComponent(final JList<?> list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
assert (c == this);
final AggregationFunction function;
if (value instanceof AggregationFunctionRow) {
function = ((AggregationFunctionRow<?>) value).getFunction();
} else if (value instanceof AggregationFunction) {
function = (AggregationFunction) value;
} else {
function = null;
}
if (function != null) {
setText(function.getLabel());
setToolTipText(function.getDescription());
}
return this;
}
use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class AggregationFunctionComboBox method contentsChanged.
@Override
public void contentsChanged(final ListDataEvent e) {
Object oldSelection = selectedItemReminder;
Object newSelection = dataModel.getSelectedItem();
if (oldSelection == newSelection) {
return;
}
if ((oldSelection == null || oldSelection instanceof AggregationFunction) && (newSelection instanceof AggregationFunction)) {
final AggregationFunction oldFunction = (AggregationFunction) oldSelection;
final AggregationFunction newFunction = (AggregationFunction) newSelection;
if (oldFunction == null || !oldFunction.getId().equals(newFunction.getId())) {
selectedItemChanged();
if (!m_selectingItem) {
fireActionEvent();
}
}
} else {
super.contentsChanged(e);
}
}
use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class DBGroupByNodeModel2 method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) inSpecs[0];
final DataTableSpec tableSpec = dbSpec.getDataTableSpec();
final DatabaseQueryConnectionSettings connection = dbSpec.getConnectionSettings(null);
final String dbIdentifier = connection.getDatabaseIdentifier();
final List<DBColumnAggregationFunctionRow> columnFunctions = DBColumnAggregationFunctionRow.loadFunctions(m_settings, DBGroupByNodeModel2.CFG_AGGREGATION_FUNCTIONS, dbIdentifier, tableSpec);
final ArrayList<DBColumnAggregationFunctionRow> invalidColAggrs = new ArrayList<>(1);
final Set<String> usedColNames = new HashSet<>(tableSpec.getNumColumns());
usedColNames.addAll(m_groupByCols.getIncludeList());
m_aggregationFunction2Use.clear();
for (DBColumnAggregationFunctionRow row : columnFunctions) {
final DataColumnSpec columnSpec = row.getColumnSpec();
final DataColumnSpec inputSpec = tableSpec.getColumnSpec(columnSpec.getName());
final AggregationFunction function = row.getFunction();
if (inputSpec == null || !inputSpec.getType().equals(columnSpec.getType())) {
invalidColAggrs.add(row);
continue;
}
if (function instanceof InvalidAggregationFunction) {
throw new InvalidSettingsException(((InvalidAggregationFunction) function).getErrorMessage());
}
if (function.hasOptionalSettings()) {
try {
function.configure(tableSpec);
} catch (InvalidSettingsException e) {
throw new InvalidSettingsException("Exception in aggregation function " + function.getLabel() + " of column " + row.getColumnSpec().getName() + ": " + e.getMessage());
}
}
usedColNames.add(row.getColumnSpec().getName());
m_aggregationFunction2Use.add(row);
}
final List<DBPatternAggregationFunctionRow> patternFunctions = DBPatternAggregationFunctionRow.loadFunctions(m_settings, CFG_PATTERN_AGGREGATION_FUNCTIONS, dbIdentifier, tableSpec);
if (tableSpec.getNumColumns() > usedColNames.size() && !patternFunctions.isEmpty()) {
for (final DataColumnSpec spec : tableSpec) {
if (!usedColNames.contains(spec.getName())) {
for (final DBPatternAggregationFunctionRow patternFunction : patternFunctions) {
final Pattern pattern = patternFunction.getRegexPattern();
final DBAggregationFunction function = patternFunction.getFunction();
if (pattern != null && pattern.matcher(spec.getName()).matches() && function.isCompatible(spec.getType())) {
final DBColumnAggregationFunctionRow row = new DBColumnAggregationFunctionRow(spec, patternFunction.getFunction());
m_aggregationFunction2Use.add(row);
usedColNames.add(spec.getName());
}
}
}
}
}
final List<DBDataTypeAggregationFunctionRow> typeFunctions = DBDataTypeAggregationFunctionRow.loadFunctions(m_settings, CFG_TYPE_AGGREGATION_FUNCTIONS, dbIdentifier, tableSpec);
// check if some columns are left
if (tableSpec.getNumColumns() > usedColNames.size() && !typeFunctions.isEmpty()) {
for (final DataColumnSpec spec : tableSpec) {
if (!usedColNames.contains(spec.getName())) {
final DataType dataType = spec.getType();
for (final DBDataTypeAggregationFunctionRow typeAggregator : typeFunctions) {
if (typeAggregator.isCompatibleType(dataType)) {
final DBColumnAggregationFunctionRow row = new DBColumnAggregationFunctionRow(spec, typeAggregator.getFunction());
m_aggregationFunction2Use.add(row);
usedColNames.add(spec.getName());
}
}
}
}
}
if (m_groupByCols.getIncludeList().isEmpty() && m_aggregationFunction2Use.isEmpty() && !m_addCountStar.getBooleanValue()) {
throw new InvalidSettingsException("Please select at least one group or aggregation function or the " + "COUNT(*) option.");
}
if (!invalidColAggrs.isEmpty()) {
setWarningMessage(invalidColAggrs.size() + " aggregation functions ignored due to incompatible columns.");
}
return new PortObjectSpec[] { createDbOutSpec(dbSpec, true) };
}
Aggregations