use of org.knime.core.data.DataColumnSpecCreator 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.DataColumnSpecCreator 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.DataColumnSpecCreator in project knime-core by knime.
the class DateTimeToStringNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final RowInput in = (RowInput) inputs[0];
final RowOutput out = (RowOutput) outputs[0];
final DataTableSpec inSpec = in.getDataTableSpec();
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
final boolean isReplace = m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE);
DataRow row;
while ((row = in.poll()) != null) {
exec.checkCanceled();
DataCell[] datacells = new DataCell[includeIndeces.length];
for (int i = 0; i < includeIndeces.length; i++) {
if (isReplace) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includeList[i], StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includeList[i] + m_suffix.getStringValue(), StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColSpec, includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
}
}
if (isReplace) {
out.push(new ReplacedColumnsDataRow(row, datacells, includeIndeces));
} else {
out.push(new AppendedColumnRow(row, datacells));
}
}
in.close();
out.close();
}
};
}
use of org.knime.core.data.DataColumnSpecCreator 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.DataColumnSpecCreator 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;
}
Aggregations