use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class StringToDateTimeNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final ColumnRearranger columnRearranger = createColumnRearranger(inData[0].getDataTableSpec());
final BufferedDataTable out = exec.createColumnRearrangeTable(inData[0], columnRearranger, exec);
if (m_failCounter > 0) {
setWarningMessage(m_failCounter + " rows could not be converted. Check the message in the missing cells for details.");
}
return new BufferedDataTable[] { out };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class StringToDurationPeriodNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable in = inData[0];
if (m_type.getStringValue().equals(OutputType.Automatic.name())) {
DataTableRowInput rowInput = new DataTableRowInput(in);
try {
detectTypes(rowInput);
} finally {
rowInput.close();
}
// no more rows to look at, guess that column is Period, if it was not detected
for (int i = 0; i < m_detectedTypes.length; i++) {
if (m_detectedTypes[i] == null) {
m_detectedTypes[i] = PeriodCellFactory.TYPE;
}
}
}
final ColumnRearranger r = createColumnRearranger(in.getDataTableSpec());
final BufferedDataTable out = exec.createColumnRearrangeTable(in, r, exec);
if (m_failCounter > 0) {
setWarningMessage(m_failCounter + " rows could not be converted. Check the message in the missing cells for details.");
}
return new BufferedDataTable[] { out };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class StringToDurationPeriodNodeModel method createColumnRearranger.
private ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
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 (final String includedCol : includeList) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, m_detectedTypes[i]);
final StringToDurationPeriodCellFactory cellFac = new StringToDurationPeriodCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++]);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(spec).newColumn(includedCol + m_suffix.getStringValue(), m_detectedTypes[i]);
final StringToDurationPeriodCellFactory cellFac = new StringToDurationPeriodCellFactory(dataColSpec, includeIndices[i++]);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class DateTimeDifferenceNodeModel method createColumnRearranger.
private ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
final ColumnRearranger rearranger = new ColumnRearranger(spec);
final ZonedDateTime fixedDateTime;
if (m_modusSelectModel.getStringValue().equals(ModusOptions.UseExecutionTime.name())) {
fixedDateTime = ZonedDateTime.now();
} else if (m_modusSelectModel.getStringValue().equals(ModusOptions.UseFixedTime.name())) {
fixedDateTime = m_fixedDateTimeModel.getZonedDateTime();
} else {
fixedDateTime = null;
}
final int colIdx1 = spec.findColumnIndex(m_col1stSelectModel.getStringValue());
final int colIdx2 = spec.findColumnIndex(m_col2ndSelectModel.getStringValue());
final AbstractCellFactory cellFac;
final DataType type = spec.getColumnSpec(colIdx1).getType();
if (type.isCompatible(LocalDateValue.class)) {
cellFac = new DateDifferenceCellFactory(colIdx1, colIdx2, fixedDateTime == null ? null : fixedDateTime.toLocalDate(), createColumnSpec(spec));
} else {
cellFac = new TimeDifferenceCellFactory(colIdx1, colIdx2, fixedDateTime, createColumnSpec(spec));
}
rearranger.append(cellFac);
return rearranger;
}
use of org.knime.core.data.container.ColumnRearranger 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;
}
Aggregations