Search in sources :

Example 1 with AppendedColumnRow

use of org.knime.core.data.append.AppendedColumnRow 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();
        }
    };
}
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) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTime(java.time.LocalDateTime) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow) LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) ExecutionContext(org.knime.core.node.ExecutionContext) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset) DataCell(org.knime.core.data.DataCell) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) RowInput(org.knime.core.node.streamable.RowInput) 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) TimeUnit(java.util.concurrent.TimeUnit) BufferedDataTable(org.knime.core.node.BufferedDataTable) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) InputPortRole(org.knime.core.node.streamable.InputPortRole) LocalDate(java.time.LocalDate) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) RowOutput(org.knime.core.node.streamable.RowOutput) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) RowInput(org.knime.core.node.streamable.RowInput) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) DataRow(org.knime.core.data.DataRow) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow)

Example 2 with AppendedColumnRow

use of org.knime.core.data.append.AppendedColumnRow 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();
        }
    };
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) Locale(java.util.Locale) ChangeListener(javax.swing.event.ChangeListener) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue) ChangeEvent(javax.swing.event.ChangeEvent) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) Collection(java.util.Collection) Set(java.util.Set) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) NodeModel(org.knime.core.node.NodeModel) LocalDateCell(org.knime.core.data.time.localdate.LocalDateCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) InputPortRole(org.knime.core.node.streamable.InputPortRole) StringHistory(org.knime.core.node.util.StringHistory) 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) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow) LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) ExecutionContext(org.knime.core.node.ExecutionContext) LocaleUtils(org.apache.commons.lang3.LocaleUtils) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataCell(org.knime.core.data.DataCell) LinkedHashSet(java.util.LinkedHashSet) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) StringCellFactory(org.knime.core.data.def.StringCell.StringCellFactory) 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) UnsupportedTemporalTypeException(java.time.temporal.UnsupportedTemporalTypeException) 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) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) MissingCell(org.knime.core.data.MissingCell) DateTimeFormatter(java.time.format.DateTimeFormatter) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StringCell(org.knime.core.data.def.StringCell) DataType(org.knime.core.data.DataType) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) RowInput(org.knime.core.node.streamable.RowInput) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) DataRow(org.knime.core.data.DataRow) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow)

Example 3 with AppendedColumnRow

use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.

the class ExtractMissingValueCauseNodeModel method execute.

/**
 * helper method to compute output
 */
private void execute(final RowInput inData, final RowOutput output, final ExecutionContext exec, final long rowCount) throws Exception {
    final AppendErrorMessageCellFactory cellFactory = createCellFactory(inData.getDataTableSpec());
    DataRow row;
    long currentRowIndex = 0;
    while ((row = inData.poll()) != null) {
        exec.checkCanceled();
        // set progress if not streaming
        if (rowCount >= 0) {
            exec.setProgress(currentRowIndex / (double) rowCount);
        }
        final long currentRowIndexFinal = currentRowIndex;
        exec.setMessage(() -> "Row " + currentRowIndexFinal + "/" + rowCount);
        // compute new cells
        Optional<DataCell[]> newCellsOptional = cellFactory.getCellsOptional(row);
        if (newCellsOptional.isPresent()) {
            DataCell[] newCells = newCellsOptional.get();
            output.push(new AppendedColumnRow(row, newCells));
        }
        currentRowIndex += 1;
    }
    inData.close();
    output.close();
}
Also used : DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow)

Example 4 with AppendedColumnRow

use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.

the class StringToDurationPeriodNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        private SimpleStreamableOperatorInternals m_internals = new SimpleStreamableOperatorInternals();

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            final RowInput rowInput = (RowInput) inputs[0];
            final DataRow row = rowInput.poll();
            if (row != null) {
                final DataTableSpec inSpec = rowInput.getDataTableSpec();
                final int[] includeIndexes = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
                final Config config = m_internals.getConfig();
                // detect types
                detectTypes(new OneRowAdditionalRowInput(rowInput, row));
                for (int i = 0; i < m_detectedTypes.length; i++) {
                    config.addDataType("detected_type" + i, m_detectedTypes[i]);
                }
                // write detected types and column names into config
                if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
                    for (int i = 0; i < rowInput.getDataTableSpec().getNumColumns(); i++) {
                        final int searchIdx = Arrays.binarySearch(includeIndexes, i);
                        config.addString("colname" + i, inSpec.getColumnNames()[i]);
                        if (searchIdx < 0) {
                            config.addDataType("type" + i, inSpec.getColumnSpec(i).getType());
                        } else {
                            config.addDataType("type" + i, m_detectedTypes[searchIdx] != null ? m_detectedTypes[searchIdx] : null);
                        }
                    }
                    config.addInt("sizeRow", rowInput.getDataTableSpec().getNumColumns());
                } else {
                    for (int i = 0; i < inSpec.getNumColumns(); i++) {
                        config.addString("colname" + i, inSpec.getColumnNames()[i]);
                        config.addDataType("type" + i, inSpec.getColumnSpec(i).getType());
                    }
                    for (int i = 0; i < m_detectedTypes.length; i++) {
                        config.addString("colname" + (i + inSpec.getNumColumns()), new UniqueNameGenerator(inSpec).newName(inSpec.getColumnSpec(includeIndexes[i]).getName() + m_suffix.getStringValue()));
                        config.addDataType("type" + (i + inSpec.getNumColumns()), m_detectedTypes[i]);
                    }
                    config.addInt("sizeRow", inSpec.getNumColumns() + m_detectedTypes.length);
                }
                config.addBoolean("needsIteration", false);
            } else {
                m_internals.getConfig().addInt("sizeRow", 0);
            }
            rowInput.close();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return m_internals;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_internals = (SimpleStreamableOperatorInternals) internals;
        }

        @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 int[] includeIndexes = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
            // read detected types from config
            final DataType[] detectedTypes = new DataType[includeIndexes.length];
            final Config config = m_internals.getConfig();
            for (int i = 0; i < includeIndexes.length; i++) {
                detectedTypes[i] = config.getDataType("detected_type" + i, null);
            }
            // compute every row
            DataRow row;
            while ((row = in.poll()) != null) {
                exec.checkCanceled();
                DataCell[] datacells = new DataCell[includeIndexes.length];
                for (int i = 0; i < includeIndexes.length; i++) {
                    if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
                        final StringToDurationPeriodCellFactory cellFac = new StringToDurationPeriodCellFactory(new DataColumnSpecCreator(inSpec.getColumnNames()[includeIndexes[i]], detectedTypes[i]).createSpec(), includeIndexes[i]);
                        datacells[i] = cellFac.getCells(row)[0];
                    } else {
                        final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(inSpec.getColumnNames()[includeIndexes[i]] + m_suffix.getStringValue(), detectedTypes[i]);
                        final StringToDurationPeriodCellFactory cellFac = new StringToDurationPeriodCellFactory(dataColSpec, includeIndexes[i]);
                        datacells[i] = cellFac.getCells(row)[0];
                    }
                }
                if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
                    out.push(new ReplacedColumnsDataRow(row, datacells, includeIndexes));
                } else {
                    out.push(new AppendedColumnRow(row, datacells));
                }
            }
            in.close();
            out.close();
        }
    };
}
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) DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Config(org.knime.core.node.config.Config) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) DataRow(org.knime.core.data.DataRow) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow)

Example 5 with AppendedColumnRow

use of org.knime.core.data.append.AppendedColumnRow in project knime-core by knime.

the class DateTimeDifferenceNodeModel method execute.

/**
 * helper method to compute output
 */
private void execute(final RowInput inData, final RowOutput output, final ExecutionContext exec, final long rowCount) throws Exception {
    DataRow row;
    DataRow previousRow = inData.poll();
    final int colIdx1 = inData.getDataTableSpec().findColumnIndex(m_col1stSelectModel.getStringValue());
    final DataType type = inData.getDataTableSpec().getColumnSpec(colIdx1).getType();
    long currentRowIndex = 0;
    output.push(new AppendedColumnRow(previousRow, new MissingCell("No previous row for calculating difference available.")));
    while ((row = inData.poll()) != null) {
        exec.checkCanceled();
        // set progress if not streaming
        if (rowCount >= 0) {
            exec.setProgress(currentRowIndex / (double) rowCount);
        }
        final long currentRowIndexFinal = currentRowIndex;
        exec.setMessage(() -> "Row " + currentRowIndexFinal + "/" + rowCount);
        // compute new cells
        DataCell newCell;
        if (type.isCompatible(LocalDateValue.class)) {
            newCell = calculateDate(previousRow.getCell(colIdx1), row.getCell(colIdx1), null);
        } else {
            newCell = calculateTime(previousRow.getCell(colIdx1), row.getCell(colIdx1), null);
        }
        output.push(new AppendedColumnRow(row, newCell));
        previousRow = row;
        currentRowIndex++;
    }
    inData.close();
    output.close();
}
Also used : MissingCell(org.knime.core.data.MissingCell) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow)

Aggregations

DataCell (org.knime.core.data.DataCell)8 DataRow (org.knime.core.data.DataRow)8 AppendedColumnRow (org.knime.core.data.append.AppendedColumnRow)8 DataTableSpec (org.knime.core.data.DataTableSpec)6 IOException (java.io.IOException)5 DataColumnSpec (org.knime.core.data.DataColumnSpec)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)5 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)5 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)5 UniqueNameGenerator (org.knime.core.util.UniqueNameGenerator)5 File (java.io.File)4 Arrays (java.util.Arrays)4 ReplacedColumnsDataRow (org.knime.base.data.replace.ReplacedColumnsDataRow)4 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)4 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)4 ExecutionContext (org.knime.core.node.ExecutionContext)4 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)4 NodeModel (org.knime.core.node.NodeModel)4 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)4