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 };
}
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;
}
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;
}
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() };
}
Aggregations