Search in sources :

Example 21 with ColumnRearranger

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

Example 22 with ColumnRearranger

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 };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput)

Example 23 with ColumnRearranger

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;
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow) ExecutionContext(org.knime.core.node.ExecutionContext) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LinkedList(java.util.LinkedList) DataCell(org.knime.core.data.DataCell) StringValue(org.knime.core.data.StringValue) InputFilter(org.knime.core.node.util.filter.InputFilter) PortInput(org.knime.core.node.streamable.PortInput) DurationPeriodFormatUtils(org.knime.time.util.DurationPeriodFormatUtils) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) DurationCellFactory(org.knime.core.data.time.duration.DurationCellFactory) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) RowInput(org.knime.core.node.streamable.RowInput) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) OutputPortRole(org.knime.core.node.streamable.OutputPortRole) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) NodeModel(org.knime.core.node.NodeModel) 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) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) InputPortRole(org.knime.core.node.streamable.InputPortRole) MissingCell(org.knime.core.data.MissingCell) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) Config(org.knime.core.node.config.Config) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) DataType(org.knime.core.data.DataType) PeriodCellFactory(org.knime.core.data.time.period.PeriodCellFactory) MergeOperator(org.knime.core.node.streamable.MergeOperator) RowOutput(org.knime.core.node.streamable.RowOutput) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) 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 24 with ColumnRearranger

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;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ZonedDateTime(java.time.ZonedDateTime) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) DataType(org.knime.core.data.DataType)

Example 25 with ColumnRearranger

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;
}
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)

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