use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class NewToOldTimeNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public StreamableOperatorInternals saveInternals() {
return null;
}
@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();
String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(includeList).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
DataRow row;
while ((row = in.poll()) != null) {
exec.checkCanceled();
DataCell[] datacells = new DataCell[includeIndeces.length];
for (int i = 0; i < includeIndeces.length; i++) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includeList[i], DateAndTimeCell.TYPE);
final ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i]);
datacells[i] = cellFac.getCells(row)[0];
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includeList[i] + m_suffix.getStringValue(), DateAndTimeCell.TYPE);
final ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColSpec, includeIndeces[i]);
datacells[i] = cellFac.getCells(row)[0];
}
}
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
out.push(new ReplacedColumnsDataRow(row, datacells, includeIndeces));
} else {
out.push(new AppendedColumnRow(row, datacells));
}
}
in.close();
out.close();
}
};
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class StringToDateTimeNodeModel 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[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
int i = 0;
for (String includedCol : includeList) {
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, DateTimeType.valueOf(m_selectedType).getDataType());
final StringToTimeCellFactory cellFac = new StringToTimeCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i++]);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), DateTimeType.valueOf(m_selectedType).getDataType());
final StringToTimeCellFactory cellFac = new StringToTimeCellFactory(dataColSpec, includeIndeces[i++]);
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class StringToDurationPeriodNodeModel method computeFinalOutputSpecs.
@Override
public PortObjectSpec[] computeFinalOutputSpecs(final StreamableOperatorInternals internals, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (m_type.getStringValue().equals(OutputType.Automatic.name())) {
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 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.DataColumnSpec in project knime-core by knime.
the class ExtendedStatisticsNodeModel method configure.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec inputSpec = inSpecs[0];
if (!m_hasSettings) {
m_nominalFilter.loadDefaults(inputSpec, new DataTypeColumnFilter(NominalValue.class, StringValue.class, IntValue.class, LongValue.class, BooleanValue.class), true);
}
List<String> nominalValues = Arrays.asList(m_nominalFilter.applyTo(inputSpec).getIncludes());
DataTableSpec nominalSpec = Statistics3Table.createOutSpecNominal(inputSpec, nominalValues);
nominalSpec = renamedOccurrencesSpec(nominalSpec);
DataTableSpec[] ret = new DataTableSpec[3];
DataTableSpecCreator specCreator = new DataTableSpecCreator(Statistics3Table.getStatisticsSpecification());
final HistogramColumn hc = createHistogramColumn();
final DataColumnSpec histogramColumnSpec = hc.createHistogramColumnSpec();
specCreator.addColumns(histogramColumnSpec);
ret[0] = specCreator.createSpec();
ret[1] = hc.createNominalHistogramTableSpec();
ret[2] = nominalSpec;
return ret;
}
Aggregations