Search in sources :

Example 61 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class ModifyDateNodeModel method createColumnRearranger.

/**
 * @param inSpec table input spec
 * @return the CR describing the output
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) {
    final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
    final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
    final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
    // determine the data type of output
    DataType dataType;
    if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_REMOVE)) {
        dataType = LocalTimeCellFactory.TYPE;
    } else {
        if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
            dataType = LocalDateTimeCellFactory.TYPE;
        } else {
            if (m_timeZone.useZone()) {
                dataType = ZonedDateTimeCellFactory.TYPE;
            } else {
                dataType = LocalDateTimeCellFactory.TYPE;
            }
        }
    }
    final ZoneId zone = m_timeZone.getZone();
    int i = 0;
    for (final String includedCol : includeList) {
        if (inSpec.getColumnSpec(includedCol).getType().equals(ZonedDateTimeCellFactory.TYPE) && m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
            dataType = ZonedDateTimeCellFactory.TYPE;
        }
        if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
            final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, dataType);
            final SingleCellFactory cellFac = createCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++], zone);
            rearranger.replace(cellFac, includedCol);
        } else {
            final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), dataType);
            final SingleCellFactory cellFac = createCellFactory(dataColSpec, includeIndices[i++], zone);
            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) DataTypeColumnFilter(org.knime.core.node.util.filter.column.DataTypeColumnFilter) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTime(java.time.LocalDateTime) LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) SettingsModelIntegerBounded(org.knime.core.node.defaultnodesettings.SettingsModelIntegerBounded) 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) DataCell(org.knime.core.data.DataCell) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) ZoneId(java.time.ZoneId) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) LocalDate(java.time.LocalDate) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) SettingsModelDateTime(org.knime.time.util.SettingsModelDateTime) DataType(org.knime.core.data.DataType) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) ZoneId(java.time.ZoneId) DataType(org.knime.core.data.DataType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 62 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class MovingAggregationNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    if (inData == null || inData.length != 1) {
        throw new InvalidSettingsException("No input table available");
    }
    final BufferedDataTable table = inData[0];
    if (table.getRowCount() == 0) {
        setWarningMessage("Empty input table found");
    } else if (!m_cumulativeComputing.getBooleanValue() && table.getRowCount() < m_winLength.getIntValue()) {
        throw new InvalidSettingsException("Window length is larger than the number of rows of the input table");
    }
    final DataTableSpec spec = table.getDataTableSpec();
    final MovingAggregationTableFactory tableFactory = createTableFactory(FileStoreFactory.createWorkflowFileStoreFactory(exec), spec);
    BufferedDataTable resultTable = tableFactory.createTable(exec, table);
    return new BufferedDataTable[] { resultTable };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 63 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class MovingAggregationNodeModel method configure.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    if (inSpecs == null || inSpecs.length != 1) {
        throw new InvalidSettingsException("No input table specification available");
    }
    final DataTableSpec inputSpec = inSpecs[0];
    m_columnAggregators2Use.clear();
    final ArrayList<ColumnAggregator> invalidColAggrs = new ArrayList<>(1);
    m_columnAggregators2Use.addAll(GroupByNodeModel.getAggregators(inputSpec, Collections.EMPTY_LIST, m_columnAggregators, m_patternAggregators, m_dataTypeAggregators, invalidColAggrs));
    if (m_columnAggregators2Use.isEmpty()) {
        setWarningMessage("No aggregation column defined");
    }
    if (!invalidColAggrs.isEmpty()) {
        setWarningMessage(invalidColAggrs.size() + " invalid aggregation column(s) found.");
    }
    LOGGER.debug(m_columnAggregators2Use);
    final MovingAggregationTableFactory tableFactory = createTableFactory(FileStoreFactory.createNotInWorkflowFileStoreFactory(), inputSpec);
    return new DataTableSpec[] { tableFactory.createResultSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList)

Example 64 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class TimeFieldExtractorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = inSpecs[0];
    // contains timestamp?
    if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
        throw new InvalidSettingsException("No timestamp found in input table!");
    }
    // currently selected column still there?
    String selectedColName = m_selectedColumn.getStringValue();
    if (selectedColName != null && !selectedColName.isEmpty()) {
        if (!inSpec.containsName(selectedColName)) {
            throw new InvalidSettingsException("Column " + selectedColName + " not found in input spec!");
        }
    } else {
        // no value set: auto-configure -> choose first timeseries
        for (DataColumnSpec colSpec : inSpec) {
            if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
                String colName = colSpec.getName();
                m_selectedColumn.setStringValue(colName);
                setWarningMessage("Auto-configure: selected " + colName);
                break;
            }
        }
    }
    // create outputspec
    ColumnRearranger colRearranger = createColumnRearranger(inSpec).getColumnRearranger();
    return new DataTableSpec[] { colRearranger.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 65 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class DateGeneratorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    validateDates(m_to);
    final Calendar from;
    if (m_useExecution.getBooleanValue()) {
        from = Calendar.getInstance(TimeZone.getDefault());
        from.setTimeInMillis(System.currentTimeMillis() + TimeZone.getDefault().getOffset(System.currentTimeMillis()));
    // no validation of from date necessary
    } else {
        from = m_from.getCalendar();
        validateDates(m_from);
    }
    int noRows = m_noOfRows.getIntValue();
    long offset = (long) calculateOffset(from, m_to.getCalendar(), noRows);
    // if no of row = 1 we simply return the start date
    if (Math.abs(offset) <= 0 && noRows > 1) {
        setWarningMessage("Number of rows too large for entered time period! " + "All rows will contain the same time stamp.");
    }
    return new DataTableSpec[] { createOutSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) Calendar(java.util.Calendar) SettingsModelCalendar(org.knime.timeseries.util.SettingsModelCalendar)

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