use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class BasisFunctionFactory method createModelSpec.
/**
* Creates a model spec based on the data input spec by extracting all
* {@link org.knime.core.data.def.DoubleCell} columns and the specified
* target column.
*
* @param inSpec the input data spec
* @param dataColumns the data columns used for training
* @param targetColumns the target classification columns
* @return a new table spec with a number of
* {@link org.knime.core.data.def.DoubleCell}s and
* the target column last
* @param type the type for the model columns
*/
public static final DataTableSpec createModelSpec(final DataTableSpec inSpec, final String[] dataColumns, final String[] targetColumns, final DataType type) {
// list of final columns in table spec
ArrayList<DataColumnSpec> list = new ArrayList<DataColumnSpec>();
// find all double and integer columns
for (String dataColumn : dataColumns) {
DataColumnSpec cSpec = inSpec.getColumnSpec(dataColumn);
assert (cSpec.getType().isCompatible(DoubleValue.class));
DataColumnSpecCreator newCSpec = new DataColumnSpecCreator(cSpec);
newCSpec.setType(type);
newCSpec.setDomain(cSpec.getDomain());
list.add(newCSpec.createSpec());
}
// if no numeric columns available
if (list.size() == 0) {
return new DataTableSpec();
}
// add the target columns
DataColumnSpec target0 = inSpec.getColumnSpec(targetColumns[0]);
if (targetColumns.length > 1 && target0.getType().isCompatible(DoubleValue.class)) {
StringCell[] targetStrings = new StringCell[targetColumns.length];
for (int i = 0; i < targetColumns.length; i++) {
targetStrings[i] = new StringCell(targetColumns[i]);
}
DataColumnSpecCreator cSpec = new DataColumnSpecCreator(CLASS_COLUMN);
cSpec.setDomain(new DataColumnDomainCreator(targetStrings).createDomain());
list.add(cSpec.createSpec());
} else {
assert (targetColumns.length == 1);
DataColumnSpecCreator cSpec = new DataColumnSpecCreator(target0);
cSpec.setType(StringCell.TYPE);
list.add(target0);
}
// add additional rule info
list.add(WEIGHT_COLUMN);
list.add(SPREAD_COLUMN);
list.add(FEATURES_COLUMN);
list.add(VARIANCE_COLUMN);
// new table spec
return new DataTableSpec(list.toArray(new DataColumnSpec[] {}));
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class EditNumericDomainNodeModel method calculateAndCreateBoundedColumnSpec.
/**
* @param currCell
* @param dataColumnSpec
* @return
*/
private DataColumnSpec calculateAndCreateBoundedColumnSpec(final DataCell currCell, final DataColumnSpec dataColumnSpec) {
DataColumnSpecCreator creator = new DataColumnSpecCreator(dataColumnSpec);
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(dataColumnSpec.getDomain());
if (!dataColumnSpec.getDomain().hasLowerBound() || DOUBLE_VALUE_COMPARATOR.compare(currCell, dataColumnSpec.getDomain().getLowerBound()) < 0) {
domainCreator.setLowerBound(currCell);
}
if (!dataColumnSpec.getDomain().hasUpperBound() || DOUBLE_VALUE_COMPARATOR.compare(currCell, dataColumnSpec.getDomain().getUpperBound()) > 0) {
domainCreator.setUpperBound(currCell);
}
creator.setDomain(domainCreator.createDomain());
return creator.createSpec();
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class RegressionPredictorCellFactory method createColumnSpec.
/**
* Creates the spec of the output if possible.
*
* @param portSpec the spec of the pmml input port
* @param tableSpec the spec of the data input port
* @param settings settings for the predictor node
* @return The spec of the output or null
* @throws InvalidSettingsException when tableSpec and portSpec do not match
*/
public static DataColumnSpec[] createColumnSpec(final PMMLPortObjectSpec portSpec, final DataTableSpec tableSpec, final RegressionPredictorSettings settings) throws InvalidSettingsException {
// Assertions
if (portSpec.getTargetCols().isEmpty()) {
throw new InvalidSettingsException("The general regression model" + " does not specify a target column.");
}
for (DataColumnSpec learningColSpec : portSpec.getLearningCols()) {
String learningCol = learningColSpec.getName();
if (tableSpec.containsName(learningCol)) {
DataColumnSpec colSpec = tableSpec.getColumnSpec(learningCol);
if (learningColSpec.getType().isCompatible(NominalValue.class)) {
if (!colSpec.getType().isCompatible(BitVectorValue.class) && !colSpec.getType().isCompatible(ByteVectorValue.class) && !colSpec.getType().isCompatible(NominalValue.class)) {
throw new InvalidSettingsException("The column \"" + learningCol + "\" in the table of prediction " + "is expected to be compatible with " + "\"NominalValue\".");
}
} else if (learningColSpec.getType().isCompatible(DoubleValue.class) && !colSpec.getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("The column \"" + learningCol + "\" in the table of prediction " + "is expected to be numeric.");
}
} else {
throw new InvalidSettingsException("The table for prediction " + "does not contain the column \"" + learningCol + "\".");
}
}
// The list of added columns
List<DataColumnSpec> newColsSpec = new ArrayList<DataColumnSpec>();
String targetCol = portSpec.getTargetFields().get(0);
DataColumnSpec targetColSpec = portSpec.getDataTableSpec().getColumnSpec(targetCol);
if (settings.getIncludeProbabilities() && targetColSpec.getType().isCompatible(NominalValue.class)) {
if (!targetColSpec.getDomain().hasValues()) {
return null;
}
List<DataCell> targetCategories = new ArrayList<DataCell>();
targetCategories.addAll(targetColSpec.getDomain().getValues());
for (DataCell value : targetCategories) {
String name = "P (" + targetCol + "=" + value.toString() + ")" + settings.getPropColumnSuffix();
String newColName = DataTableSpec.getUniqueColumnName(tableSpec, name);
DataColumnSpecCreator colSpecCreator = new DataColumnSpecCreator(newColName, DoubleCell.TYPE);
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(new DoubleCell(0.0), new DoubleCell(1.0));
colSpecCreator.setDomain(domainCreator.createDomain());
newColsSpec.add(colSpecCreator.createSpec());
}
}
String targetColName = settings.getHasCustomPredictionName() ? settings.getCustomPredictionName() : "Prediction (" + targetCol + ")";
String uniqueTargetColName = DataTableSpec.getUniqueColumnName(tableSpec, targetColName);
DataType targetType = targetColSpec.getType().isCompatible(NominalValue.class) ? targetColSpec.getType() : DoubleCell.TYPE;
DataColumnSpecCreator targetColSpecCreator = new DataColumnSpecCreator(uniqueTargetColName, targetType);
if (targetColSpec.getType().isCompatible(NominalValue.class)) {
DataColumnDomainCreator targetDomainCreator = new DataColumnDomainCreator(targetColSpec.getDomain());
targetColSpecCreator.setDomain(targetDomainCreator.createDomain());
}
newColsSpec.add(targetColSpecCreator.createSpec());
return newColsSpec.toArray(new DataColumnSpec[0]);
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class AppendedRowsTable method merge.
/*
* Merges two domains of the same column, i.e. emerging from different
* tables, min max will be updated (if possible) and the possible value set.
*/
private static final DataColumnDomain merge(final DataColumnDomain d1, final DataColumnDomain d2, final DataValueComparator comp) {
final DataCell d1Min = d1.getLowerBound();
final DataCell d1Max = d1.getUpperBound();
final DataCell d2Min = d2.getLowerBound();
final DataCell d2Max = d2.getUpperBound();
final Set<DataCell> d1Poss = d1.getValues();
final Set<DataCell> d2Poss = d2.getValues();
final DataCell newMin;
if (d1Min == null || d2Min == null) {
newMin = null;
} else {
newMin = comp.compare(d1Min, d2Min) < 0 ? d1Min : d2Min;
}
final DataCell newMax;
if (d1Max == null || d2Max == null) {
newMax = null;
} else {
newMax = comp.compare(d1Max, d2Max) > 0 ? d1Max : d2Max;
}
final Set<DataCell> newPoss;
if (d1Poss == null || d2Poss == null) {
newPoss = null;
} else {
newPoss = new LinkedHashSet<DataCell>(d1Poss);
newPoss.addAll(d2Poss);
}
return new DataColumnDomainCreator(newPoss, newMin, newMax).createDomain();
}
use of org.knime.core.data.DataColumnDomainCreator 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;
}
Aggregations