use of org.knime.core.node.port.database.DatabasePortObjectSpec 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 };
}
Aggregations