use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBColumnRenameNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) inSpecs[0];
final DatabasePortObjectSpec outSpec = createDBOutSpec(dbSpec);
return new PortObjectSpec[] { outSpec };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBGroupByNodeDialog2 method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
if (specs == null || specs.length < 1 || specs[0] == null) {
throw new NotConfigurableException("No input connection found.");
}
final DatabasePortObjectSpec dbspec = (DatabasePortObjectSpec) specs[0];
final DataTableSpec spec = dbspec.getDataTableSpec();
try {
final DatabaseQueryConnectionSettings connectionSettings = dbspec.getConnectionSettings(null);
m_columnNamePolicy.loadSettingsFrom(settings);
final String dbIdentifier = connectionSettings.getDatabaseIdentifier();
m_aggregationPanel.loadSettingsFrom(settings, dbIdentifier, spec);
m_patternPanel.loadSettingsFrom(settings, dbIdentifier, spec);
m_typePanel.loadSettingsFrom(settings, dbIdentifier, spec);
m_addCountStar.loadSettingsFrom(settings);
m_countStarColName.loadSettingsFrom(settings);
final DBAggregationFunctionProvider functionProvider = new DBAggregationFunctionProvider(connectionSettings.getUtility());
m_descriptionTab.removeAll();
final GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
m_descriptionTab.add(functionProvider.getDescriptionPane(), c);
} catch (final InvalidSettingsException e) {
throw new NotConfigurableException(e.getMessage());
}
m_groupCol.loadSettingsFrom(settings, new DataTableSpec[] { spec });
columnsChanged();
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBGroupByNodeModel2 method createDbOutSpec.
/**
* @param inSpec Spec of the input database object
* @param checkRetrieveMetadata true if the retrieveMetadataInConfigure settings should be respected,
* <code>false</code> if the metadata should be retrieved in any case (for execute)
* @return Spec of the output database object
* @throws InvalidSettingsException If the current settings are invalid
*/
private DatabasePortObjectSpec createDbOutSpec(final DatabasePortObjectSpec inSpec, final boolean checkRetrieveMetadata) throws InvalidSettingsException {
DatabaseQueryConnectionSettings connection = inSpec.getConnectionSettings(getCredentialsProvider());
final StatementManipulator statementManipulator = connection.getUtility().getStatementManipulator();
final String newQuery = createQuery(connection, connection.getQuery(), statementManipulator);
connection = createDBQueryConnection(inSpec, newQuery);
if (checkRetrieveMetadata && !connection.getRetrieveMetadataInConfigure()) {
return null;
}
final DataTableSpec tableSpec = createOutSpec(inSpec.getDataTableSpec(), connection, newQuery, statementManipulator, checkRetrieveMetadata);
return new DatabasePortObjectSpec(tableSpec, connection.createConnectionModel());
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec 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) };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class ParameterizedDBQueryPanel method loadSettingsFrom.
void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs, final Collection<FlowVariable> flowVariables) {
try {
m_appendInputColsModel.loadSettingsFrom(settings);
m_includeEmptyResultsModel.loadSettingsFrom(settings);
m_retainAllColumnsModel.loadSettingsFrom(settings);
m_failIfExceptionModel.loadSettingsFrom(settings);
m_editor.setText(settings.getString(ParameterizedDBQueryNodeModel.CFG_SQL_STATEMENT, ParameterizedDBQueryNodeModel.getDefaultSQLStatement()));
} catch (InvalidSettingsException ex) {
m_appendInputColsModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_APPEND_INPUT_COL);
m_includeEmptyResultsModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_INCLUDE_EMPTY_RESULTS);
m_retainAllColumnsModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_RETAIN_ALL_COLUMNS);
m_failIfExceptionModel.setBooleanValue(ParameterizedDBQueryNodeModel.DEF_FAIL_IF_EXCEPTION);
}
updateKnimeColumns((DataTableSpec) specs[0]);
updateDBColumns(((DatabasePortObjectSpec) specs[1]).getDataTableSpec());
updateFlowVariables(flowVariables.toArray(new FlowVariable[flowVariables.size()]));
if (specs[1] != null && specs[1] instanceof DatabasePortObjectSpec) {
final DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) specs[1];
final DatabaseUtility dbUtility = DatabaseUtility.getUtility(dbSpec.getDatabaseIdentifier());
m_statementManipulator = dbUtility.getStatementManipulator();
}
}
Aggregations