use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class DBPivotNodeModel 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(getCredentialsProvider());
final String dbIdentifier = connection.getDatabaseIdentifier();
final List<DBColumnAggregationFunctionRow> columnFunctions = DBColumnAggregationFunctionRow.loadFunctions(m_settings, DBPivotNodeModel.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());
usedColNames.addAll(m_pivotCols.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("Wrong aggregation function configuration '" + function.getLabel() + "' of column '" + row.getColumnSpec().getName() + "': " + e.getMessage(), e);
}
}
usedColNames.add(row.getColumnSpec().getName());
m_aggregationFunction2Use.add(row);
}
if (m_aggregationFunction2Use.isEmpty()) {
throw new InvalidSettingsException("No aggregation columns selected.");
}
if (m_groupByCols.getIncludeList().isEmpty()) {
setWarningMessage("No grouping column included. Aggregate complete table");
}
if (m_pivotCols.getIncludeList().isEmpty()) {
throw new InvalidSettingsException("No pivot columns selected.");
}
if (!invalidColAggrs.isEmpty()) {
setWarningMessage(invalidColAggrs.size() + " aggregation functions ignored due to incompatible columns.");
}
final DatabasePortObjectSpec resultSpec;
if (connection.getRetrieveMetadataInConfigure()) {
try {
resultSpec = createDbOutSpec(dbSpec, new ExecutionMonitor());
} catch (CanceledExecutionException e) {
throw new InvalidSettingsException(e.getMessage());
}
} else {
resultSpec = null;
}
return new PortObjectSpec[] { resultSpec };
}
use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class AggregationFunctionComboBox method update.
/**
* @param type the {@link DataType} used to initialize this combobox
* @param list {@link List} of {@link AggregationMethod}s the user can choose from
* @param selected the current selected method
*/
public void update(final DataType type, final List<? extends AggregationFunction> list, final AggregationFunction selected) {
if (m_type == null || !m_type.equals(type)) {
// recreate the combo box if the type has change
removeAllItems();
for (final AggregationFunction method : list) {
addItem(method);
}
// save the current type for comparison
m_type = type;
}
// select the previous selected item
setSelectedItem(selected);
}
use of org.knime.core.node.port.database.aggregation.AggregationFunction in project knime-core by knime.
the class AggregationFunctionComboBox method setSelectedItem.
@Override
public void setSelectedItem(final Object anObject) {
Object objectToSelect = null;
if (anObject != null && !isEditable()) {
final AggregationFunction functionToSelect;
if (anObject instanceof AggregationFunctionRow<?>) {
functionToSelect = ((AggregationFunctionRow<?>) anObject).getFunction();
} else if (anObject instanceof AggregationFunction) {
functionToSelect = (AggregationFunction) anObject;
} else {
functionToSelect = null;
}
if (functionToSelect != null) {
// For non editable combo boxes, an invalid selection
// will be rejected.
boolean found = false;
for (int i = 0; i < dataModel.getSize(); i++) {
AggregationFunction element = dataModel.getElementAt(i);
if (functionToSelect.getId().equals(element.getId())) {
found = true;
objectToSelect = element;
break;
}
}
if (!found) {
return;
}
}
// Must toggle the state of this flag since this method
// call may result in ListDataEvents being fired.
m_selectingItem = true;
dataModel.setSelectedItem(objectToSelect);
m_selectingItem = false;
if (selectedItemReminder != dataModel.getSelectedItem()) {
// in case a users implementation of ComboBoxModel
// doesn't fire a ListDataEvent when the selection
// changes.
selectedItemChanged();
}
}
fireActionEvent();
}
Aggregations