use of org.knime.core.data.container.ColumnRearranger 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.container.ColumnRearranger in project knime-core by knime.
the class OldToNewTimeNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
m_colSelect.loadDefaults(inSpecs[0]);
m_selectedNewType = DateTimeType.LOCAL_DATE.name();
}
final ColumnRearranger columnRearranger = createColumnRearranger(inSpecs[0], null);
if (columnRearranger == null) {
return new DataTableSpec[] { null };
} else {
return new DataTableSpec[] { columnRearranger.createSpec() };
}
}
use of org.knime.core.data.container.ColumnRearranger 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.container.ColumnRearranger 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;
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class StringManipulationNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec inSpec = inData[0].getDataTableSpec();
ColumnRearranger c = createColumnRearranger(inSpec);
m_rowCount = inData[0].size();
try {
BufferedDataTable o = exec.createColumnRearrangeTable(inData[0], c, exec);
return new BufferedDataTable[] { o };
} finally {
m_rowCount = -1L;
}
}
Aggregations