Search in sources :

Example 96 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec 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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidAggregationFunction) ArrayList(java.util.ArrayList) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) InvalidAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidAggregationFunction) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) AggregationFunction(org.knime.core.node.port.database.aggregation.AggregationFunction) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) DBColumnAggregationFunctionRow(org.knime.base.node.io.database.groupby.dialog.column.DBColumnAggregationFunctionRow) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) HashSet(java.util.HashSet)

Example 97 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class DBTableCreatorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if (inSpecs[0] == null && !(inSpecs[0] instanceof DatabaseConnectionPortObjectSpec)) {
        throw new InvalidSettingsException("No valid database connection available.");
    }
    final DatabaseConnectionPortObjectSpec dbSpec = (DatabaseConnectionPortObjectSpec) inSpecs[0];
    m_config.setTableSpec((DataTableSpec) inSpecs[1]);
    final boolean isColumnsEmpty = m_config.getColumns().isEmpty();
    if (m_config.getTableSpec() != null && (m_config.useDynamicSettings() || isColumnsEmpty)) {
        m_config.loadColumnSettingsFromTableSpec(m_config.getTableSpec());
        m_config.updateKeysWithDynamicSettings();
    }
    if (m_config.getTableSpec() == null && m_config.useDynamicSettings()) {
        throw new InvalidSettingsException("Dynamic settings enabled but no input table available.");
    }
    if (isColumnsEmpty) {
        throw new InvalidSettingsException("At least one column must be defined.");
    }
    final DatabaseConnectionSettings conn = dbSpec.getConnectionSettings(getCredentialsProvider());
    final DBTableCreator tableCreator = conn.getUtility().getTableCreator(m_config.getSchema(), getTableName(), m_config.isTempTable());
    final List<DBColumn> columns = m_config.getColumns();
    final List<DBKey> keys = m_config.getKeys();
    try {
        tableCreator.validateSettings(m_config.ifNotExists(), columns.toArray(new DBColumn[columns.size()]), keys.toArray(new DBKey[keys.size()]), m_config.getAdditionalOptions());
    } catch (Exception e) {
        throw new InvalidSettingsException(e.getMessage());
    }
    pushFlowVariables(tableCreator.getSchema(), tableCreator.getTableName());
    return new PortObjectSpec[] { dbSpec };
}
Also used : DBTableCreator(org.knime.core.node.port.database.tablecreator.DBTableCreator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec) DBColumn(org.knime.core.node.port.database.tablecreator.DBColumn) DBKey(org.knime.core.node.port.database.tablecreator.DBKey) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 98 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class DBReaderDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    if (m_showConnectionPanel) {
        m_connectionPane.loadSettingsFrom(settings, specs, getCredentialsProvider());
    }
    DatabaseQueryConnectionSettings s = new DatabaseQueryConnectionSettings();
    try {
        s.loadValidatedConnection(settings, getCredentialsProvider());
    } catch (InvalidSettingsException ex) {
    // use settings as they are
    }
    // statement
    String statement = s.getQuery();
    m_statmnt.setText(statement == null ? "SELECT * FROM " + DatabaseQueryConnectionSettings.TABLE_PLACEHOLDER : statement);
    // select the table placeholder statement for easier replacements
    selectPlaceHolder(m_statmnt, DatabaseQueryConnectionSettings.TABLE_PLACEHOLDER);
    // update list of flow/workflow variables
    m_listModelVars.removeAllElements();
    for (Map.Entry<String, FlowVariable> e : getAvailableFlowVariables().entrySet()) {
        m_listModelVars.addElement(e.getValue());
    }
    // read execute without configure checkbox
    if (runWithoutConfigure()) {
        m_configureBox.setSelected(!s.getValidateQuery());
    }
    m_upstreamConnectionSettings = null;
    for (PortObjectSpec pos : specs) {
        if (pos instanceof DatabaseConnectionPortObjectSpec) {
            try {
                m_upstreamConnectionSettings = ((DatabaseConnectionPortObjectSpec) pos).getConnectionSettings(getCredentialsProvider());
            } catch (InvalidSettingsException ex) {
                LOGGER.warn("Could not load database connection from upstream node: " + ex.getMessage(), ex);
            }
        }
    }
    if (m_upstreamConnectionSettings != null || !m_showConnectionPanel) {
        m_connectionPane.setVisible(false);
    } else {
        m_connectionPane.setVisible(true);
    }
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec) Map(java.util.Map) FlowVariable(org.knime.core.node.workflow.FlowVariable) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 99 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class NormalizerNodeModel method prepareConfigure.

/**
 * @param inSpecs An array of DataTableSpecs (as many as this model has
 *            inputs).
 * @return An array of DataTableSpecs (as many as this model has outputs)
 *
 * @throws InvalidSettingsException if the <code>#configure()</code> failed,
 *             that is, the settings are inconsistent with given
 *             DataTableSpec elements.
 */
protected PortObjectSpec[] prepareConfigure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec spec = (DataTableSpec) inSpecs[0];
    // extract selected numeric columns
    updateNumericColumnSelection(spec);
    if (m_mode == NONORM_MODE) {
        return new PortObjectSpec[] { spec, new DataTableSpec() };
    }
    DataTableSpec modelSpec = FilterColumnTable.createFilterTableSpec(spec, m_columns);
    return new PortObjectSpec[] { Normalizer.generateNewSpec(spec, m_columns), modelSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec)

Example 100 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class Normalizer2NodeModel method prepareConfigure.

/**
 * @param inSpecs An array of DataTableSpecs (as many as this model has
 *            inputs).
 * @return An array of DataTableSpecs (as many as this model has outputs)
 *
 * @throws InvalidSettingsException if the <code>#configure()</code> failed,
 *             that is, the settings are inconsistent with given
 *             DataTableSpec elements.
 */
protected PortObjectSpec[] prepareConfigure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec spec = (DataTableSpec) inSpecs[0];
    // extract selected numeric columns
    updateNumericColumnSelection(spec);
    if (m_mode == NONORM_MODE) {
        return new PortObjectSpec[] { spec, new DataTableSpec() };
    }
    DataTableSpec modelSpec = FilterColumnTable.createFilterTableSpec(spec, m_columns);
    return new PortObjectSpec[] { Normalizer2.generateNewSpec(spec, m_columns), modelSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec)

Aggregations

PortObjectSpec (org.knime.core.node.port.PortObjectSpec)139 DataTableSpec (org.knime.core.data.DataTableSpec)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)86 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)35 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)30 DataColumnSpec (org.knime.core.data.DataColumnSpec)29 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)25 IOException (java.io.IOException)24 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)24 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)24 PortObject (org.knime.core.node.port.PortObject)19 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)16 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)16 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)14 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)12 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)12 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)12