use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class ModifyTimeNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) {
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
// determine the data type of output
DataType dataType;
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_REMOVE)) {
dataType = LocalDateCellFactory.TYPE;
} else {
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = LocalDateTimeCellFactory.TYPE;
} else {
if (m_timeZone.useZone()) {
dataType = ZonedDateTimeCellFactory.TYPE;
} else {
dataType = LocalDateTimeCellFactory.TYPE;
}
}
}
int i = 0;
for (final String includedCol : includeList) {
if (inSpec.getColumnSpec(includedCol).getType().equals(ZonedDateTimeCellFactory.TYPE) && m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = ZonedDateTimeCellFactory.TYPE;
}
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, dataType);
final SingleCellFactory cellFac = createCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++], m_timeZone.getZone());
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), dataType);
final SingleCellFactory cellFac = createCellFactory(dataColSpec, includeIndices[i++], m_timeZone.getZone());
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class ModifyTimeNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
throw new InvalidSettingsException("Node must be configured!");
}
DataTableSpec in = inSpecs[0];
ColumnRearranger r = createColumnRearranger(in);
DataTableSpec out = r.createSpec();
return new DataTableSpec[] { out };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class ModifyDateNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
throw new InvalidSettingsException("Node must be configured!");
}
DataTableSpec in = inSpecs[0];
ColumnRearranger r = createColumnRearranger(in);
DataTableSpec out = r.createSpec();
return new DataTableSpec[] { out };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class ModifyDateNodeModel method createColumnRearranger.
/**
* @param inSpec table input spec
* @return the CR describing the output
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) {
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
// determine the data type of output
DataType dataType;
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_REMOVE)) {
dataType = LocalTimeCellFactory.TYPE;
} else {
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = LocalDateTimeCellFactory.TYPE;
} else {
if (m_timeZone.useZone()) {
dataType = ZonedDateTimeCellFactory.TYPE;
} else {
dataType = LocalDateTimeCellFactory.TYPE;
}
}
}
final ZoneId zone = m_timeZone.getZone();
int i = 0;
for (final String includedCol : includeList) {
if (inSpec.getColumnSpec(includedCol).getType().equals(ZonedDateTimeCellFactory.TYPE) && m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = ZonedDateTimeCellFactory.TYPE;
}
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, dataType);
final SingleCellFactory cellFac = createCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++], zone);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), dataType);
final SingleCellFactory cellFac = createCellFactory(dataColSpec, includeIndices[i++], zone);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class TimeFieldExtractorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = inSpecs[0];
// contains timestamp?
if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
throw new InvalidSettingsException("No timestamp found in input table!");
}
// currently selected column still there?
String selectedColName = m_selectedColumn.getStringValue();
if (selectedColName != null && !selectedColName.isEmpty()) {
if (!inSpec.containsName(selectedColName)) {
throw new InvalidSettingsException("Column " + selectedColName + " not found in input spec!");
}
} else {
// no value set: auto-configure -> choose first timeseries
for (DataColumnSpec colSpec : inSpec) {
if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
String colName = colSpec.getName();
m_selectedColumn.setStringValue(colName);
setWarningMessage("Auto-configure: selected " + colName);
break;
}
}
}
// create outputspec
ColumnRearranger colRearranger = createColumnRearranger(inSpec).getColumnRearranger();
return new DataTableSpec[] { colRearranger.createSpec() };
}
Aggregations