use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class DatabaseHelper method createTableSpec.
/**
* Creates <code>DataTableSpec</code> from the given <code>ResultSetMetaData</code>
* @param meta the <code>ResultSetMetaData</code> used to create <code>DataTableSpec</code>
* @return a {@link DataTableSpec} created from the given {@link ResultSetMetaData}
* @throws SQLException
*/
protected DataTableSpec createTableSpec(final ResultSetMetaData meta) throws SQLException {
int cols = meta.getColumnCount();
if (cols == 0) {
return new DataTableSpec("database");
}
StatementManipulator manipulator = m_conn.getUtility().getStatementManipulator();
DataTableSpec spec = null;
for (int i = 0; i < cols; i++) {
int dbIdx = i + 1;
String name = manipulator.unquoteColumn(meta.getColumnLabel(dbIdx));
int type = meta.getColumnType(dbIdx);
DataType newType = getKNIMEType(type, meta, dbIdx);
if (spec == null) {
spec = new DataTableSpec("database", new DataColumnSpecCreator(name, newType).createSpec());
} else {
name = DataTableSpec.getUniqueColumnName(spec, name);
spec = new DataTableSpec("database", spec, new DataTableSpec(new DataColumnSpecCreator(name, newType).createSpec()));
}
}
return spec;
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class DatabaseReaderConnection method createTableSpec.
private DataTableSpec createTableSpec(final ResultSetMetaData meta) throws SQLException {
int cols = meta.getColumnCount();
if (cols == 0) {
return new DataTableSpec("database");
}
StatementManipulator manipulator = m_conn.getUtility().getStatementManipulator();
DataTableSpec spec = null;
for (int i = 0; i < cols; i++) {
int dbIdx = i + 1;
String name = manipulator.unquoteColumn(meta.getColumnLabel(dbIdx));
int type = meta.getColumnType(dbIdx);
DataType newType;
switch(type) {
// all types that can be interpreted as integer
case Types.BIT:
case Types.BOOLEAN:
newType = BooleanCell.TYPE;
break;
// all types that can be interpreted as integer
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
newType = IntCell.TYPE;
break;
// all types that can be interpreted as long
case Types.BIGINT:
newType = LongCell.TYPE;
break;
// all types that can be interpreted as double
case Types.FLOAT:
case Types.DOUBLE:
case Types.NUMERIC:
case Types.DECIMAL:
case Types.REAL:
newType = DoubleCell.TYPE;
break;
// all types that can be interpreted as data-and-time
case Types.TIME:
case Types.DATE:
case Types.TIMESTAMP:
newType = DateAndTimeCell.TYPE;
break;
// all types that can be interpreted as binary object
case Types.BLOB:
case Types.LONGVARBINARY:
case Types.BINARY:
newType = BinaryObjectDataCell.TYPE;
break;
// fallback string
default:
newType = StringCell.TYPE;
}
if (spec == null) {
spec = new DataTableSpec("database", new DataColumnSpecCreator(name, newType).createSpec());
} else {
name = DataTableSpec.getUniqueColumnName(spec, name);
spec = new DataTableSpec("database", spec, new DataTableSpec(new DataColumnSpecCreator(name, newType).createSpec()));
}
}
return spec;
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class ColumnRearranger method ensureColumnIsConverted.
/**
* @param converter
* @param index
* @since 2.7
*/
public final void ensureColumnIsConverted(final DataCellTypeConverter converter, final int index) {
SpecAndFactoryObject current = m_includes.get(index);
DataType converterOutputType = converter.getOutputType();
DataColumnSpec colSpec = current.getColSpec();
if (converterOutputType.equals(colSpec.getType())) {
LOGGER.debug("Converting column \"" + colSpec.getName() + "\" not required.");
} else {
LOGGER.debug("Converting column \"" + colSpec.getName() + "\" required.");
DataColumnSpecCreator c = new DataColumnSpecCreator(colSpec);
c.setType(converterOutputType);
DataCellTypeConverterCellFactory cellConverter = new DataCellTypeConverterCellFactory(c.createSpec(), converter, index);
replace(cellConverter, index);
}
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class ColumnSelectionPanel method update.
/**
* Updates this filter panel by removing all current items and adding the
* columns according to the content of the argument <code>spec</code>. If
* a column name is provided and it is not filtered out the corresponding
* item in the combo box will be selected.
*
* @param spec To get the column names, types and the current index from.
* @param selColName The column name to be set as chosen.
* @param addSelColIfInvalid adds the selected column although it does not
* not exist in the given spec or is filtered by the filter.
* The column is added at the end and rendered with a red border.
* @param useRowID set this parameter to <code>true</code> and the
* selColName to <code>null</code> if the the row id option should be
* selected
* @throws NotConfigurableException If the spec does not contain at least
* one compatible type.
* @since 2.10
*/
public final void update(final DataTableSpec spec, final String selColName, final boolean useRowID, final boolean addSelColIfInvalid) throws NotConfigurableException {
m_spec = spec;
m_chooser.removeAllItems();
if (m_addNoneColOption) {
final String noneOption = DataTableSpec.getUniqueColumnName(spec, NONE_OPTION_LABEL);
m_noneColSpec = new DataColumnSpecCreator(noneOption, DataType.getMissingCell().getType()).createSpec();
m_chooser.addItem(m_noneColSpec);
m_chooser.setToolTipText("Select " + noneOption + " for no column");
}
if (m_addRowIDOption) {
final String rowIDOption = DataTableSpec.getUniqueColumnName(spec, ROWID_OPTION_LABEL);
m_rowIDColSpec = new DataColumnSpecCreator(rowIDOption, DataType.getMissingCell().getType()).createSpec();
m_chooser.addItem(m_rowIDColSpec);
m_chooser.setToolTipText("Select " + rowIDOption + " for RowID");
}
DataColumnSpec selectMe = null;
if (spec != null) {
for (DataColumnSpec current : spec) {
if (m_columnFilter.includeColumn(current)) {
m_chooser.addItem(current);
if (current.getName().equals(selColName)) {
selectMe = current;
}
}
}
if (selectMe != null) {
m_chooser.setSelectedItem(selectMe);
} else {
if (addSelColIfInvalid && selColName != null) {
m_chooser.addItem(DataColumnSpecListCellRenderer.createInvalidSpec(selColName));
}
if (m_addNoneColOption && !useRowID) {
m_chooser.setSelectedItem(m_noneColSpec);
} else if (m_addRowIDOption && useRowID) {
m_chooser.setSelectedItem(m_rowIDColSpec);
} else {
// select last element
final int size = m_chooser.getItemCount();
if (size > 0) {
m_chooser.setSelectedIndex(size - 1);
}
}
}
}
if ((m_chooser.getItemCount() == 0 || containsOnlyTheInvalidColumn(addSelColIfInvalid, selectMe)) && m_isRequired) {
throw new NotConfigurableException(m_columnFilter.allFilteredMsg());
}
}
use of org.knime.core.data.DataColumnSpecCreator in project knime-core by knime.
the class DataColumnSpecListCellRenderer method createInvalidSpec.
/**
* @param originalSpec the original {@link DataColumnSpec} to be marked as invalid
* @return the given {@link DataColumnSpec} with the added invalid flag
* @since 2.8
* @see #INVALID_PROPERTY_NAME
*/
public static final DataColumnSpec createInvalidSpec(final DataColumnSpec originalSpec) {
DataColumnSpecCreator creator = new DataColumnSpecCreator(originalSpec);
final DataColumnProperties origProps = originalSpec.getProperties();
final Map<String, String> map = creaeteInvalidPropertiesMap();
final DataColumnProperties props;
if (origProps != null) {
props = origProps.cloneAndOverwrite(map);
} else {
props = new DataColumnProperties(map);
}
creator.setProperties(props);
final DataColumnSpec invalidSpec = creator.createSpec();
return invalidSpec;
}
Aggregations