Search in sources :

Example 1 with LocalDateValue

use of org.knime.core.data.time.localdate.LocalDateValue in project knime-core by knime.

the class DateTimeBasedRowFilterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable dataTable = inData[0];
    final BufferedDataContainer container = exec.createDataContainer(dataTable.getDataTableSpec());
    // read input
    final int colIdx = dataTable.getDataTableSpec().findColumnIndex(m_colSelect.getStringValue());
    final ZonedDateTime executionStartTime = m_startAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
    final ZonedDateTime executionEndTime = m_endAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
    // filter rows
    for (final DataRow row : dataTable) {
        exec.checkCanceled();
        final DataCell cell = row.getCell(colIdx);
        if (!cell.isMissing()) {
            if (cell instanceof LocalDateValue && filterRowLocalDate(((LocalDateValue) cell).getLocalDate(), executionStartTime, executionEndTime)) {
                container.addRowToTable(row);
            } else if (cell instanceof LocalTimeValue && filterRowLocalTime(((LocalTimeValue) cell).getLocalTime(), executionStartTime, executionEndTime)) {
                container.addRowToTable(row);
            } else if (cell instanceof LocalDateTimeValue && filterRowLocalDateTime(((LocalDateTimeValue) cell).getLocalDateTime(), executionStartTime, executionEndTime)) {
                container.addRowToTable(row);
            } else if (cell instanceof ZonedDateTimeValue && filterRowZonedDateTime(((ZonedDateTimeValue) cell).getZonedDateTime(), executionStartTime, executionEndTime)) {
                container.addRowToTable(row);
            }
        }
    }
    container.close();
    return new BufferedDataTable[] { container.getTable() };
}
Also used : LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ZonedDateTime(java.time.ZonedDateTime) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) DataRow(org.knime.core.data.DataRow) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue)

Example 2 with LocalDateValue

use of org.knime.core.data.time.localdate.LocalDateValue in project knime-core by knime.

the class LocalDateMedianOperator method createCustomMeanMedianMethod.

private static EvenListMedianMethod createCustomMeanMedianMethod() {
    return new EvenListMedianMethod() {

        @Override
        public DataCell extractMedian(final List<DataCell> cells, final int lowerCandidateIdx, final int upperCandidateIdx) {
            final LocalDate date1 = ((LocalDateValue) cells.get(lowerCandidateIdx)).getLocalDate();
            final LocalDate date2 = ((LocalDateValue) cells.get(upperCandidateIdx)).getLocalDate();
            // calculate mean, truncate/round down fraction of day
            final long meanTimestamp = (long) ((date1.toEpochDay() + date2.toEpochDay()) / 2.0);
            final LocalDate meanDate = LocalDate.ofEpochDay(meanTimestamp);
            return LocalDateCellFactory.create(meanDate);
        }
    };
}
Also used : List(java.util.List) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) LocalDate(java.time.LocalDate)

Example 3 with LocalDateValue

use of org.knime.core.data.time.localdate.LocalDateValue in project knime-core by knime.

the class ExtractDateTimeFieldsNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    final String selectedCol = m_colSelectModel.getStringValue();
    if (selectedCol == null || selectedCol.isEmpty()) {
        throw new InvalidSettingsException("Node must be configured.");
    }
    final int selectedColIdx = spec.findColumnIndex(selectedCol);
    if (selectedColIdx < 0) {
        throw new InvalidSettingsException("Column " + selectedCol + " not found in the input table.");
    }
    final DataType selectedColType = spec.getColumnSpec(selectedCol).getType();
    final boolean isDate = isDateType(selectedColType);
    final boolean isTime = isTimeType(selectedColType);
    if (!isDate && !isTime) {
        throw new InvalidSettingsException("Column " + selectedCol + " does not contain a Date&Time type.");
    }
    final boolean isLocalDate = selectedColType.isCompatible(LocalDateValue.class);
    final boolean isLocalTime = selectedColType.isCompatible(LocalTimeValue.class);
    final boolean isLocalDateTime = selectedColType.isCompatible(LocalDateTimeValue.class);
    final boolean isZonedDateTime = selectedColType.isCompatible(ZonedDateTimeValue.class);
    final Locale locale = LocaleUtils.toLocale(m_localeModel.getStringValue());
    final UniqueNameGenerator nameGenerator = new UniqueNameGenerator(spec);
    final DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
    final ColumnRearranger rearranger = new ColumnRearranger(spec);
    if (isDate) {
        if (m_yearModel.getBooleanValue()) {
            final DataColumnSpec colSpec = nameGenerator.newColumn(YEAR, IntCell.TYPE);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return IntCellFactory.create(value.getLocalDate().getYear());
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().getYear());
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().getYear());
                    }
                });
            }
        }
        if (m_quarterModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, QUARTER, 1, 4);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return IntCellFactory.create((value.getLocalDate().getMonthValue() + 2) / 3);
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create((value.getLocalDateTime().getMonthValue() + 2) / 3);
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create((value.getZonedDateTime().getMonthValue() + 2) / 3);
                    }
                });
            }
        }
        if (m_monthNumberModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, MONTH_NUMBER, 1, 12);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return IntCellFactory.create(value.getLocalDate().getMonthValue());
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().getMonthValue());
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().getMonthValue());
                    }
                });
            }
        }
        if (m_monthNameModel.getBooleanValue()) {
            final DataColumnSpec colSpec = nameGenerator.newColumn(MONTH_NAME, StringCell.TYPE);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return StringCellFactory.create(value.getLocalDate().getMonth().getDisplayName(TextStyle.FULL, locale));
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return StringCellFactory.create(value.getLocalDateTime().getMonth().getDisplayName(TextStyle.FULL, locale));
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return StringCellFactory.create(value.getZonedDateTime().getMonth().getDisplayName(TextStyle.FULL, locale));
                    }
                });
            }
        }
        if (m_weekModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, WEEK, 1, 52);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return IntCellFactory.create(value.getLocalDate().get(WeekFields.of(locale).weekOfWeekBasedYear()));
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().get(WeekFields.of(locale).weekOfWeekBasedYear()));
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().get(WeekFields.of(locale).weekOfWeekBasedYear()));
                    }
                });
            }
        }
        if (m_dayYearModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, DAY_OF_YEAR, 1, 366);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return IntCellFactory.create(value.getLocalDate().getDayOfYear());
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().getDayOfYear());
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().getDayOfYear());
                    }
                });
            }
        }
        if (m_dayMonthModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, DAY_OF_MONTH, 1, 31);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return IntCellFactory.create(value.getLocalDate().getDayOfMonth());
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().getDayOfMonth());
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().getDayOfMonth());
                    }
                });
            }
        }
        if (m_dayWeekNumberModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, DAY_OF_WEEK_NUMBER, 1, 7);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return IntCellFactory.create(value.getLocalDate().get(WeekFields.of(locale).dayOfWeek()));
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().get(WeekFields.of(locale).dayOfWeek()));
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().get(WeekFields.of(locale).dayOfWeek()));
                    }
                });
            }
        }
        if (m_dayWeekNameModel.getBooleanValue()) {
            final DataColumnSpec colSpec = nameGenerator.newColumn(DAY_OF_WEEK_NAME, StringCell.TYPE);
            if (isLocalDate) {
                rearranger.append(new AbstractLocalDateFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateValue value) {
                        return StringCellFactory.create(value.getLocalDate().getDayOfWeek().getDisplayName(TextStyle.FULL_STANDALONE, locale));
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return StringCellFactory.create(value.getLocalDateTime().getDayOfWeek().getDisplayName(TextStyle.FULL_STANDALONE, locale));
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return StringCellFactory.create(value.getZonedDateTime().getDayOfWeek().getDisplayName(TextStyle.FULL_STANDALONE, locale));
                    }
                });
            }
        }
    }
    if (isTime) {
        if (m_hourModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, HOUR, 0, 23);
            if (isLocalTime) {
                rearranger.append(new AbstractLocalTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalTimeValue value) {
                        return IntCellFactory.create(value.getLocalTime().getHour());
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().getHour());
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().getHour());
                    }
                });
            }
        }
        if (m_minuteModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, MINUTE, 0, 59);
            if (isLocalTime) {
                rearranger.append(new AbstractLocalTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalTimeValue value) {
                        return IntCellFactory.create(value.getLocalTime().getMinute());
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().getMinute());
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().getMinute());
                    }
                });
            }
        }
        if (m_secondModel.getBooleanValue()) {
            final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, SECOND, 0, 59);
            if (isLocalTime) {
                rearranger.append(new AbstractLocalTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalTimeValue value) {
                        return IntCellFactory.create(value.getLocalTime().getSecond());
                    }
                });
            } else if (isLocalDateTime) {
                rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final LocalDateTimeValue value) {
                        return IntCellFactory.create(value.getLocalDateTime().getSecond());
                    }
                });
            } else if (isZonedDateTime) {
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return IntCellFactory.create(value.getZonedDateTime().getSecond());
                    }
                });
            }
        }
        if (m_subsecondModel.getBooleanValue()) {
            final String subsecondUnit = m_subsecondUnitsModel.getStringValue();
            if (subsecondUnit.equals(MILLISECOND)) {
                // in milliseconds
                final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, SUBSECOND_COL + " (in " + MILLISECOND + ")", 0, 999);
                if (isLocalTime) {
                    rearranger.append(new AbstractLocalTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final LocalTimeValue value) {
                            return IntCellFactory.create(value.getLocalTime().get(ChronoField.MILLI_OF_SECOND));
                        }
                    });
                } else if (isLocalDateTime) {
                    rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final LocalDateTimeValue value) {
                            return IntCellFactory.create(value.getLocalDateTime().get(ChronoField.MILLI_OF_SECOND));
                        }
                    });
                } else if (isZonedDateTime) {
                    rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final ZonedDateTimeValue value) {
                            return IntCellFactory.create(value.getZonedDateTime().get(ChronoField.MILLI_OF_SECOND));
                        }
                    });
                }
            } else if (subsecondUnit.equals(MICROSECOND)) {
                // in microseconds
                final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, SUBSECOND_COL + " (in " + MICROSECOND + ")", 0, 999_999);
                if (isLocalTime) {
                    rearranger.append(new AbstractLocalTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final LocalTimeValue value) {
                            return IntCellFactory.create(value.getLocalTime().get(ChronoField.MICRO_OF_SECOND));
                        }
                    });
                } else if (isLocalDateTime) {
                    rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final LocalDateTimeValue value) {
                            return IntCellFactory.create(value.getLocalDateTime().get(ChronoField.MICRO_OF_SECOND));
                        }
                    });
                } else if (isZonedDateTime) {
                    rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final ZonedDateTimeValue value) {
                            return IntCellFactory.create(value.getZonedDateTime().get(ChronoField.MICRO_OF_SECOND));
                        }
                    });
                }
            } else if (subsecondUnit.equals(NANOSECOND)) {
                // in nanoseconds
                final DataColumnSpec colSpec = createBoundedIntColumn(domainCreator, nameGenerator, SUBSECOND_COL + " (in " + NANOSECOND + ")", 0, 999_999_999);
                if (isLocalTime) {
                    rearranger.append(new AbstractLocalTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final LocalTimeValue value) {
                            return IntCellFactory.create(value.getLocalTime().getNano());
                        }
                    });
                } else if (isLocalDateTime) {
                    rearranger.append(new AbstractLocalDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final LocalDateTimeValue value) {
                            return IntCellFactory.create(value.getLocalDateTime().getNano());
                        }
                    });
                } else if (isZonedDateTime) {
                    rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                        @Override
                        protected DataCell getCell(final ZonedDateTimeValue value) {
                            return IntCellFactory.create(value.getZonedDateTime().getNano());
                        }
                    });
                }
            }
        }
        if (isZonedDateTime) {
            if (m_timeZoneNameModel.getBooleanValue()) {
                final DataColumnSpec colSpec = nameGenerator.newColumn(TIME_ZONE_NAME, StringCell.TYPE);
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return StringCellFactory.create(value.getZonedDateTime().getZone().getId().toString());
                    }
                });
            }
            if (m_timeZoneOffsetModel.getBooleanValue()) {
                final DataColumnSpec colSpec = nameGenerator.newColumn(TIME_ZONE_OFFSET, StringCell.TYPE);
                rearranger.append(new AbstractZonedDateTimeFieldCellFactory(selectedColIdx, colSpec) {

                    @Override
                    protected DataCell getCell(final ZonedDateTimeValue value) {
                        return StringCellFactory.create(value.getZonedDateTime().getOffset().getDisplayName(TextStyle.FULL_STANDALONE, locale));
                    }
                });
            }
        }
    }
    if (rearranger.getColumnCount() == spec.getNumColumns()) {
        getLogger().info("No fields will be extracted. Output table will equal input table.");
    }
    return rearranger;
}
Also used : Locale(java.util.Locale) LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue)

Example 4 with LocalDateValue

use of org.knime.core.data.time.localdate.LocalDateValue in project knime-core by knime.

the class DateTimeBasedRowFilterNodeModel 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];
            // read input
            final int colIdx = in.getDataTableSpec().findColumnIndex(m_colSelect.getStringValue());
            final ZonedDateTime executionStartTime = m_startAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
            final ZonedDateTime executionEndTime = m_endAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
            // filter rows
            final DataType colDataType = in.getDataTableSpec().getColumnSpec(colIdx).getType();
            DataRow row;
            while ((row = in.poll()) != null) {
                exec.checkCanceled();
                final DataCell cell = row.getCell(colIdx);
                if (!cell.isMissing()) {
                    if (cell instanceof LocalDateValue && filterRowLocalDate(((LocalDateValue) cell).getLocalDate(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    } else if (cell instanceof LocalTimeValue && filterRowLocalTime(((LocalTimeValue) cell).getLocalTime(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    } else if (cell instanceof LocalDateTimeValue && filterRowLocalDateTime(((LocalDateTimeValue) cell).getLocalDateTime(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    } else if (cell instanceof ZonedDateTimeValue && filterRowZonedDateTime(((ZonedDateTimeValue) cell).getZonedDateTime(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    }
                }
            }
            in.close();
            out.close();
        }
    };
}
Also used : LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) RowInput(org.knime.core.node.streamable.RowInput) DataRow(org.knime.core.data.DataRow) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) ZonedDateTime(java.time.ZonedDateTime) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue)

Aggregations

LocalDateValue (org.knime.core.data.time.localdate.LocalDateValue)4 DataCell (org.knime.core.data.DataCell)3 LocalDateTimeValue (org.knime.core.data.time.localdatetime.LocalDateTimeValue)3 LocalTimeValue (org.knime.core.data.time.localtime.LocalTimeValue)3 ZonedDateTimeValue (org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue)3 ZonedDateTime (java.time.ZonedDateTime)2 DataRow (org.knime.core.data.DataRow)2 DataType (org.knime.core.data.DataType)2 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Locale (java.util.Locale)1 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 ExecutionContext (org.knime.core.node.ExecutionContext)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1 RowInput (org.knime.core.node.streamable.RowInput)1