Search in sources :

Example 21 with DataColumnSpec

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();
        }
    };
}
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 22 with DataColumnSpec

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;
}
Also used : 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) StringUtils(org.apache.commons.lang3.StringUtils) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) ExecutionContext(org.knime.core.node.ExecutionContext) LocaleUtils(org.apache.commons.lang3.LocaleUtils) 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) Locale(java.util.Locale) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LocalTime(java.time.LocalTime) DateTimeType(org.knime.time.util.DateTimeType) DataCell(org.knime.core.data.DataCell) LinkedHashSet(java.util.LinkedHashSet) StringValue(org.knime.core.data.StringValue) InputFilter(org.knime.core.node.util.filter.InputFilter) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) Collection(java.util.Collection) Set(java.util.Set) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) 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) DateTimeParseException(java.time.format.DateTimeParseException) BufferedDataTable(org.knime.core.node.BufferedDataTable) MissingCell(org.knime.core.data.MissingCell) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) StringHistory(org.knime.core.node.util.StringHistory) 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 23 with DataColumnSpec

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] });
    }
}
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 24 with DataColumnSpec

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;
}
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 25 with DataColumnSpec

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;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataTypeColumnFilter(org.knime.core.node.util.filter.column.DataTypeColumnFilter) NominalValue(org.knime.core.data.NominalValue) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) HistogramColumn(org.knime.base.data.statistics.HistogramColumn) DataColumnSpec(org.knime.core.data.DataColumnSpec) BooleanValue(org.knime.core.data.BooleanValue) LongValue(org.knime.core.data.LongValue) StringValue(org.knime.core.data.StringValue) IntValue(org.knime.core.data.IntValue)

Aggregations

DataColumnSpec (org.knime.core.data.DataColumnSpec)800 DataTableSpec (org.knime.core.data.DataTableSpec)351 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)239 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)223 DataCell (org.knime.core.data.DataCell)187 ArrayList (java.util.ArrayList)167 DataType (org.knime.core.data.DataType)149 DataRow (org.knime.core.data.DataRow)124 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)123 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)119 DoubleValue (org.knime.core.data.DoubleValue)104 HashSet (java.util.HashSet)92 BufferedDataTable (org.knime.core.node.BufferedDataTable)77 LinkedHashSet (java.util.LinkedHashSet)65 LinkedHashMap (java.util.LinkedHashMap)56 LinkedList (java.util.LinkedList)47 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)46 DoubleCell (org.knime.core.data.def.DoubleCell)46 StringCell (org.knime.core.data.def.StringCell)45 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)43