use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class DurationPeriodToStringNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
m_colSelect.loadDefaults(spec);
}
final ColumnRearranger rearranger = new ColumnRearranger(spec);
final String[] includeList = m_colSelect.applyTo(spec).getIncludes();
final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(spec).getIncludes()).mapToInt(s -> spec.findColumnIndex(s)).toArray();
int i = 0;
for (String includedCol : includeList) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, StringCell.TYPE);
DurationPeriodToStringCellFactory cellFac = new DurationPeriodToStringCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++]);
rearranger.replace(cellFac, includedCol);
} else {
DataColumnSpec dataColSpec = new UniqueNameGenerator(spec).newColumn(includedCol + m_suffix.getStringValue(), StringCell.TYPE);
DurationPeriodToStringCellFactory cellFac = new DurationPeriodToStringCellFactory(dataColSpec, includeIndices[i++]);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class DurationToNumberNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
final ColumnRearranger rearranger = new ColumnRearranger(spec);
if (m_colSelectModel.getStringValue() == null) {
throw new InvalidSettingsException("Node must be configured!");
}
if (spec.findColumnIndex(m_colSelectModel.getStringValue()) < 0) {
throw new InvalidSettingsException("Column '" + m_colSelectModel.getStringValue() + "' not found in the input table.");
}
final boolean exact = m_typeSelectModel.getStringValue().equals(DataTypeMode.Exact.name());
final DataColumnSpec colSpec = new UniqueNameGenerator(spec).newColumn((m_durationFieldSelectModel.getStringValue()), exact ? DoubleCell.TYPE : LongCell.TYPE);
final CellFactory cellFac = new ExtractDurationSingleFieldCellFactory(spec.findColumnIndex(m_colSelectModel.getStringValue()), exact, colSpec);
rearranger.append(cellFac);
return rearranger;
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class OldToNewTimeNodeModel method computeFinalOutputSpecs.
@Override
public PortObjectSpec[] computeFinalOutputSpecs(final StreamableOperatorInternals internals, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (m_autoType.getBooleanValue()) {
final SimpleStreamableOperatorInternals simpleInternals = (SimpleStreamableOperatorInternals) internals;
final Config config = simpleInternals.getConfig();
final DataColumnSpec[] colSpecs = new DataColumnSpec[config.getInt("sizeRow")];
for (int i = 0; i < colSpecs.length; i++) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(config.getString("colname" + i), config.getDataType("type" + i));
colSpecs[i] = dataColumnSpecCreator.createSpec();
}
return new DataTableSpec[] { new DataTableSpec(colSpecs) };
} else {
return configure(new DataTableSpec[] { (DataTableSpec) inSpecs[0] });
}
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class OldToNewTimeNodeModel method createColumnRearranger.
/**
* @param inSpec Current input spec
* @return The CR describing the output, can be null if called by configure
*/
private ColumnRearranger createColumnRearranger(final DataTableSpec inSpec, final DataRow row) {
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndexes = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
final DataColumnSpec[] newColumnSpecs = getNewIncludedColumnSpecs(inSpec, row);
// if called by configure and automatic type detection is activated, it can be null
if (newColumnSpecs == null) {
return null;
}
int i = 0;
for (String includedCol : includeList) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(newColumnSpecs[i], i, includeIndexes[i++]);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(newColumnSpecs[i].getName() + m_suffix.getStringValue(), newColumnSpecs[i].getType());
ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColSpec, i, includeIndexes[i++]);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class TimestampToDateTimeNodeModel method createColumnRearranger.
/**
* @param inSpec table input spec
* @return the CR describing the output
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) throws InvalidSettingsException {
CheckUtils.checkSetting(m_hasValidatedConfiguration, "Node must be configured!");
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
int i = 0;
final boolean isReplace = m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE);
UniqueNameGenerator uniqueNameGenerator = new UniqueNameGenerator(inSpec);
for (String includedCol : includeList) {
if (isReplace) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, DateTimeType.valueOf(m_selectedType).getDataType());
final TimestampToTimeCellFactory cellFac = new TimestampToTimeCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i++]);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = uniqueNameGenerator.newColumn(includedCol + m_suffix.getStringValue(), DateTimeType.valueOf(m_selectedType).getDataType());
final TimestampToTimeCellFactory cellFac = new TimestampToTimeCellFactory(dataColSpec, includeIndeces[i++]);
rearranger.append(cellFac);
}
}
return rearranger;
}
Aggregations