use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class DBGroupByNodeModel method createOutSpec.
/**
* @param inSpec Spec of the input table
* @param checkRetrieveMetadata
* @return Spec of the output table
* @throws InvalidSettingsException if settings do not match the input specification
*/
private DataTableSpec createOutSpec(final DataTableSpec inSpec, final DatabaseConnectionSettings settings, final String query, final boolean ignoreExceptions) throws InvalidSettingsException {
// Try get spec from database
try {
DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(settings, query);
DatabaseReaderConnection conn = new DatabaseReaderConnection(querySettings);
return conn.getDataTableSpec(getCredentialsProvider());
} catch (SQLException e) {
NodeLogger.getLogger(getClass()).info("Could not determine table spec from database, trying to guess now", e);
if (!ignoreExceptions) {
throw new InvalidSettingsException("Error in automatically build sql statement: " + e.getMessage());
}
// Otherwise guess spec
}
List<DataColumnSpec> colSpecs = new ArrayList<>();
// Add all group by columns
for (String col : m_groupByCols.getIncludeList()) {
colSpecs.add(inSpec.getColumnSpec(col));
}
// Add aggregated columns
for (int i = 0; i < m_aggregatedColumns.length; i++) {
String col = m_aggregatedColumns[i];
String method = m_aggregationMethods[i];
if (inSpec.getColumnSpec(col) == null) {
throw new InvalidSettingsException("Column '" + col + "' in aggregation " + method + " does not exist");
}
final DatabaseUtility databaseUtility = settings.getUtility();
final DBAggregationFunction function = databaseUtility.getAggregationFunction(method);
// Get type of column after aggregation
DataType type = function.getType(inSpec.getColumnSpec(col).getType());
colSpecs.add(new DataColumnSpecCreator(generateColumnName(col, method), type).createSpec());
}
return new DataTableSpec(colSpecs.toArray(new DataColumnSpec[colSpecs.size()]));
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class NaiveBayesCellFactory method createResultColSpecs.
/**
* Creates the column specification of the result columns and returns
* them in the order they should be appended to the original table
* specification.
* @param classColumn the class column spec
* @param inSpec the <code>DataTableSpec</code> of the input data to check
* if the winner column name already exists
* @param inclClassProbVals if the probability values should be displayed
* @return <code>DataColumnSpec[]</code> with the column specifications
* of the result columns
*/
public static DataColumnSpec createResultColSpecs(final DataColumnSpec classColumn, final DataTableSpec inSpec, final boolean inclClassProbVals) {
if (inclClassProbVals) {
return null;
}
final String colName = DataTableSpec.getUniqueColumnName(inSpec, WINNER_COLUMN_NAME);
final DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(colName, classColumn.getType());
final DataColumnSpec classColSpec = colSpecCreator.createSpec();
return classColSpec;
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class DecTreePredictorNodeModel method createOutTableSpec.
private DataTableSpec createOutTableSpec(final PortObjectSpec[] inSpecs) {
LinkedList<DataCell> predValues = null;
if (m_showDistribution.getBooleanValue()) {
predValues = getPredictionValues((PMMLPortObjectSpec) inSpecs[INMODELPORT]);
if (predValues == null) {
// no out spec can be determined
return null;
}
}
int numCols = (predValues == null ? 0 : predValues.size()) + 1;
DataTableSpec inSpec = (DataTableSpec) inSpecs[INDATAPORT];
UniqueNameGenerator nameGenerator = new UniqueNameGenerator(inSpec);
DataColumnSpec[] newCols = new DataColumnSpec[numCols];
/* Set bar renderer and domain [0,1] as default for the double cells
* containing the distribution */
// DataColumnProperties propsRendering = new DataColumnProperties(
// Collections.singletonMap(
// DataValueRenderer.PROPERTY_PREFERRED_RENDERER,
// DoubleBarRenderer.DESCRIPTION));
DataColumnDomain domain = new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0)).createDomain();
// add all distribution columns
for (int i = 0; i < numCols - 1; i++) {
DataColumnSpecCreator colSpecCreator = nameGenerator.newCreator(predValues.get(i).toString(), DoubleCell.TYPE);
// colSpecCreator.setProperties(propsRendering);
colSpecCreator.setDomain(domain);
newCols[i] = colSpecCreator.createSpec();
}
// add the prediction column
newCols[numCols - 1] = nameGenerator.newColumn("Prediction (DecTree)", StringCell.TYPE);
DataTableSpec newColSpec = new DataTableSpec(newCols);
return new DataTableSpec(inSpec, newColSpec);
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class BitVectorGeneratorNodeModel method createNumericOutputSpec.
private DataColumnSpec createNumericOutputSpec(final DataTableSpec spec) {
String name;
int j = 0;
do {
name = "BitVectors" + (j == 0 ? "" : "_" + j);
j++;
} while (spec.containsName(name));
// get the names of numeric columns
List<String> nameMapping = new ArrayList<String>();
nameMapping.addAll(m_includedColumns.getIncludeList());
DataColumnSpecCreator creator = new DataColumnSpecCreator(name, DenseBitVectorCell.TYPE);
creator.setElementNames(nameMapping.toArray(new String[nameMapping.size()]));
return creator.createSpec();
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class BitVectorGeneratorNodeModel method createColumnRearranger.
private ColumnRearranger createColumnRearranger(final DataTableSpec spec, final int colIdx) throws InvalidSettingsException {
// BW: fixed here locally: the annotation and the column name
// are taken from input spec (21 Sep 2006)
DataColumnSpecCreator creator = new DataColumnSpecCreator(spec.getColumnSpec(colIdx));
creator.setDomain(null);
creator.setType(DenseBitVectorCell.TYPE);
if (!m_replace) {
String colName = spec.getColumnSpec(colIdx).getName() + "_bits";
creator.setName(colName);
if (spec.containsName(colName)) {
throw new InvalidSettingsException("Column " + colName + " already exist in table!");
}
}
if (m_type.equals(STRING_TYPES.BIT)) {
m_factory = new BitString2BitVectorCellFactory(creator.createSpec(), colIdx);
} else if (m_type.equals(STRING_TYPES.HEX)) {
m_factory = new Hex2BitVectorCellFactory(creator.createSpec(), colIdx);
} else if (m_type.equals(STRING_TYPES.ID)) {
m_factory = new IdString2BitVectorCellFactory(creator.createSpec(), colIdx);
} else {
throw new InvalidSettingsException("String type to parse bitvectors" + " from unknown!");
}
ColumnRearranger c = new ColumnRearranger(spec);
if (m_replace) {
c.replace(m_factory, colIdx);
} else {
c.append(m_factory);
}
return c;
}
Aggregations