Search in sources :

Example 36 with DataTableSpec

use of org.knime.core.data.DataTableSpec 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;
}
Also used : Period(java.time.Period) DurationPeriodFormatUtils(org.knime.time.util.DurationPeriodFormatUtils) Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) PeriodValue(org.knime.core.data.time.period.PeriodValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StringCellFactory(org.knime.core.data.def.StringCell.StringCellFactory) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) DurationValue(org.knime.core.data.time.duration.DurationValue) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) SimpleStreamableFunctionNodeModel(org.knime.core.node.streamable.simple.SimpleStreamableFunctionNodeModel) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Duration(java.time.Duration) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 37 with DataTableSpec

use of org.knime.core.data.DataTableSpec 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() };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger)

Example 38 with DataTableSpec

use of org.knime.core.data.DataTableSpec 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] });
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Config(org.knime.core.node.config.Config)

Example 39 with DataTableSpec

use of org.knime.core.data.DataTableSpec 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;
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) LocalTime(java.time.LocalTime) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) NodeModel(org.knime.core.node.NodeModel) LocalDateCell(org.knime.core.data.time.localdate.LocalDateCell) ZoneId(java.time.ZoneId) BufferedDataTable(org.knime.core.node.BufferedDataTable) InputPortRole(org.knime.core.node.streamable.InputPortRole) LocalDate(java.time.LocalDate) Config(org.knime.core.node.config.Config) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) LocalDateTimeCell(org.knime.core.data.time.localdatetime.LocalDateTimeCell) RowOutput(org.knime.core.node.streamable.RowOutput) DataTableSpec(org.knime.core.data.DataTableSpec) ZonedDateTimeCell(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCell) LocalDateTime(java.time.LocalDateTime) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow) ExecutionContext(org.knime.core.node.ExecutionContext) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DateTimeType(org.knime.time.util.DateTimeType) DataCell(org.knime.core.data.DataCell) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) RowInput(org.knime.core.node.streamable.RowInput) LocalTimeCell(org.knime.core.data.time.localtime.LocalTimeCell) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) OutputPortRole(org.knime.core.node.streamable.OutputPortRole) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) File(java.io.File) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PortOutput(org.knime.core.node.streamable.PortOutput) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) TimeUnit(java.util.concurrent.TimeUnit) MissingCell(org.knime.core.data.MissingCell) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataType(org.knime.core.data.DataType) MergeOperator(org.knime.core.node.streamable.MergeOperator) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 40 with DataTableSpec

use of org.knime.core.data.DataTableSpec 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;
}
Also used : LongValue(org.knime.core.data.LongValue) Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTime(java.time.LocalDateTime) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) SimpleStreamableFunctionNodeModel(org.knime.core.node.streamable.simple.SimpleStreamableFunctionNodeModel) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LocalTime(java.time.LocalTime) DateTimeType(org.knime.time.util.DateTimeType) DataCell(org.knime.core.data.DataCell) InputFilter(org.knime.core.node.util.filter.InputFilter) IntValue(org.knime.core.data.IntValue) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) Instant(java.time.Instant) ZoneId(java.time.ZoneId) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) TimeUnit(java.util.concurrent.TimeUnit) LocalDate(java.time.LocalDate) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) CheckUtils(org.knime.core.node.util.CheckUtils) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Aggregations

DataTableSpec (org.knime.core.data.DataTableSpec)938 DataColumnSpec (org.knime.core.data.DataColumnSpec)340 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)306 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)228 BufferedDataTable (org.knime.core.node.BufferedDataTable)226 DataCell (org.knime.core.data.DataCell)186 DataRow (org.knime.core.data.DataRow)170 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)136 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)129 DataType (org.knime.core.data.DataType)109 ArrayList (java.util.ArrayList)106 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)98 DoubleValue (org.knime.core.data.DoubleValue)94 DefaultRow (org.knime.core.data.def.DefaultRow)92 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)90 ExecutionContext (org.knime.core.node.ExecutionContext)68 PortObject (org.knime.core.node.port.PortObject)66 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)62 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)61 RowKey (org.knime.core.data.RowKey)59