Search in sources :

Example 26 with ColumnRearranger

use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.

the class DurationToNumberNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    final ColumnRearranger rearranger = new ColumnRearranger(spec);
    if (m_colSelectModel.getStringValue() == null) {
        throw new InvalidSettingsException("Node must be configured!");
    }
    if (spec.findColumnIndex(m_colSelectModel.getStringValue()) < 0) {
        throw new InvalidSettingsException("Column '" + m_colSelectModel.getStringValue() + "' not found in the input table.");
    }
    final boolean exact = m_typeSelectModel.getStringValue().equals(DataTypeMode.Exact.name());
    final DataColumnSpec colSpec = new UniqueNameGenerator(spec).newColumn((m_durationFieldSelectModel.getStringValue()), exact ? DoubleCell.TYPE : LongCell.TYPE);
    final CellFactory cellFac = new ExtractDurationSingleFieldCellFactory(spec.findColumnIndex(m_colSelectModel.getStringValue()), exact, colSpec);
    rearranger.append(cellFac);
    return rearranger;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) DoubleCellFactory(org.knime.core.data.def.DoubleCell.DoubleCellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) CellFactory(org.knime.core.data.container.CellFactory) LongCellFactory(org.knime.core.data.def.LongCell.LongCellFactory)

Example 27 with ColumnRearranger

use of org.knime.core.data.container.ColumnRearranger 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 28 with ColumnRearranger

use of org.knime.core.data.container.ColumnRearranger 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 29 with ColumnRearranger

use of org.knime.core.data.container.ColumnRearranger 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)

Example 30 with ColumnRearranger

use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.

the class StringManipulationNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    DataTableSpec inSpec = inData[0].getDataTableSpec();
    ColumnRearranger c = createColumnRearranger(inSpec);
    m_rowCount = inData[0].size();
    try {
        BufferedDataTable o = exec.createColumnRearrangeTable(inData[0], c, exec);
        return new BufferedDataTable[] { o };
    } finally {
        m_rowCount = -1L;
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Aggregations

ColumnRearranger (org.knime.core.data.container.ColumnRearranger)393 DataTableSpec (org.knime.core.data.DataTableSpec)221 BufferedDataTable (org.knime.core.node.BufferedDataTable)153 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 DataColumnSpec (org.knime.core.data.DataColumnSpec)116 DataRow (org.knime.core.data.DataRow)79 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)69 DataCell (org.knime.core.data.DataCell)63 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)55 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)49 ExecutionContext (org.knime.core.node.ExecutionContext)46 PortObject (org.knime.core.node.port.PortObject)39 ArrayList (java.util.ArrayList)38 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)36 DataType (org.knime.core.data.DataType)34 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)32 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)27 DoubleValue (org.knime.core.data.DoubleValue)26 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)26 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)25