Search in sources :

Example 1 with DBBinnerMaps

use of org.knime.base.node.io.database.binning.DBBinnerMaps in project knime-core by knime.

the class DBNumericBinnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setMessage("Retrieving metadata from database");
    checkDuplicateBinNames();
    final DatabasePortObject inDatabasePortObject = (DatabasePortObject) inData[0];
    final DatabasePortObjectSpec inDatabasePortObjectSpec = inDatabasePortObject.getSpec();
    DatabaseQueryConnectionSettings connectionSettings = inDatabasePortObject.getConnectionSettings(getCredentialsProvider());
    DataTableSpec outDataTableSpec = DBAutoBinner.createNewDataTableSpec(inDatabasePortObjectSpec.getDataTableSpec(), m_columnToAppended);
    PMMLPortObject outPMMLPortObject = createPMMLPortObject(inDatabasePortObjectSpec.getDataTableSpec(), outDataTableSpec);
    DBBinnerMaps binnerMaps = DBAutoBinner.intoBinnerMaps(outPMMLPortObject, inDatabasePortObjectSpec.getDataTableSpec());
    DatabasePortObjectSpec outDatabasePortObjectSpec = createDatabasePortObjectSpec(connectionSettings, inDatabasePortObjectSpec, binnerMaps);
    return new PortObject[] { new DatabasePortObject(outDatabasePortObjectSpec), outPMMLPortObject };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DBBinnerMaps(org.knime.base.node.io.database.binning.DBBinnerMaps) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 2 with DBBinnerMaps

use of org.knime.base.node.io.database.binning.DBBinnerMaps in project knime-core by knime.

the class DBAutoBinnerNodeModel method createQuery.

private String createQuery(final String query, final StatementManipulator statementManipulator, final DataTableSpec dataTableSpec, final PMMLPortObject pmmlPortObject) {
    DBBinnerMaps maps = DBAutoBinner.intoBinnerMaps(pmmlPortObject, dataTableSpec);
    String[] binningCols = m_settings.getFilterConfiguration().applyTo(dataTableSpec).getIncludes();
    String[] allColumns = dataTableSpec.getColumnNames();
    String[] additionalCols = DBAutoBinner.filter(binningCols, allColumns);
    String result = statementManipulator.getBinnerStatement(query, binningCols, additionalCols, maps.getBoundariesMap(), maps.getBoundariesOpenMap(), maps.getNamingMap(), maps.getAppendMap());
    return result;
}
Also used : DBBinnerMaps(org.knime.base.node.io.database.binning.DBBinnerMaps)

Example 3 with DBBinnerMaps

use of org.knime.base.node.io.database.binning.DBBinnerMaps in project knime-core by knime.

the class DBApplyBinnerNodeModel method createQuery.

private String createQuery(final String query, final StatementManipulator statementManipulator, final DataTableSpec dataTableSpec, final PMMLPortObject pmmlPortObject) throws InvalidSettingsException {
    DBBinnerMaps maps = DBAutoBinner.intoBinnerMaps(pmmlPortObject, dataTableSpec);
    DerivedField[] derivedFields = pmmlPortObject.getDerivedFields();
    final DataTableSpec pmmlInputSpec = pmmlPortObject.getSpec().getDataTableSpec();
    String[] includeCols = new String[derivedFields.length];
    for (int i = 0; i < pmmlPortObject.getDerivedFields().length; i++) {
        String fieldName = derivedFields[i].getDiscretize().getField();
        final DataColumnSpec colSpec = dataTableSpec.getColumnSpec(fieldName);
        if (colSpec == null) {
            throw new InvalidSettingsException("Column '" + fieldName + "' not found in input table");
        }
        DataColumnSpec pmmlInputColSpec = pmmlInputSpec.getColumnSpec(fieldName);
        assert (pmmlInputColSpec != null) : "Column '" + fieldName + "' from derived fields not found in PMML model spec";
        DataType knimeType = pmmlInputColSpec.getType();
        if (!colSpec.getType().isCompatible(knimeType.getPreferredValueClass())) {
            throw new InvalidSettingsException("Date type of column '" + fieldName + "' is not compatible with PMML model: expected '" + knimeType + "' but is '" + colSpec.getType() + "'");
        }
        includeCols[i] = fieldName;
    }
    String[] allColumns = dataTableSpec.getColumnNames();
    String[] excludeCols = filter(includeCols, allColumns);
    String result = statementManipulator.getBinnerStatement(query, includeCols, excludeCols, maps.getBoundariesMap(), maps.getBoundariesOpenMap(), maps.getNamingMap(), maps.getAppendMap());
    return result;
}
Also used : DBBinnerMaps(org.knime.base.node.io.database.binning.DBBinnerMaps) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField)

Example 4 with DBBinnerMaps

use of org.knime.base.node.io.database.binning.DBBinnerMaps in project knime-core by knime.

the class DBNumericBinnerNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DatabasePortObjectSpec inDatabasePortObjectSpec = (DatabasePortObjectSpec) inSpecs[0];
    DatabaseQueryConnectionSettings connectionSettings = inDatabasePortObjectSpec.getConnectionSettings(getCredentialsProvider());
    boolean suppCase = connectionSettings.getUtility().supportsCase();
    if (!suppCase) {
        if (m_columnToBins.size() > 1) {
            throw new InvalidSettingsException("Database does not support \"CASE\". Please choose only one column.");
        }
    }
    if (m_columnToBins.isEmpty()) {
        setWarningMessage("No columns selected for binning");
    } else {
        checkDuplicateBinNames();
    }
    DataTableSpec outDataTableSpec = DBAutoBinner.createNewDataTableSpec(inDatabasePortObjectSpec.getDataTableSpec(), m_columnToAppended);
    PMMLPortObject outPMMLPortObject = createPMMLPortObject(inDatabasePortObjectSpec.getDataTableSpec(), outDataTableSpec);
    DBBinnerMaps binnerMaps = DBAutoBinner.intoBinnerMaps(outPMMLPortObject, inDatabasePortObjectSpec.getDataTableSpec());
    DatabasePortObjectSpec outDatabasePortObjectSpec = null;
    try {
        outDatabasePortObjectSpec = createDatabasePortObjectSpec(connectionSettings, inDatabasePortObjectSpec, binnerMaps);
    } catch (InvalidKeyException | BadPaddingException | IllegalBlockSizeException | SQLException | IOException e) {
    // TODO Auto-generated catch block
    }
    return new PortObjectSpec[] { outDatabasePortObjectSpec, outPMMLPortObject.getSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SQLException(java.sql.SQLException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) BadPaddingException(javax.crypto.BadPaddingException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) DBBinnerMaps(org.knime.base.node.io.database.binning.DBBinnerMaps) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec)

Aggregations

DBBinnerMaps (org.knime.base.node.io.database.binning.DBBinnerMaps)4 DataTableSpec (org.knime.core.data.DataTableSpec)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)2 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)2 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)2 IOException (java.io.IOException)1 InvalidKeyException (java.security.InvalidKeyException)1 SQLException (java.sql.SQLException)1 BadPaddingException (javax.crypto.BadPaddingException)1 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)1 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataType (org.knime.core.data.DataType)1 PortObject (org.knime.core.node.port.PortObject)1 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1 DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)1 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)1