@Override public Time toIndexValue(final PersistentDataset<Object> adapterPersistenceEncoding) { final Object startObj = adapterPersistenceEncoding.getValue(nativeStartTimeHandler.getFieldName()); final Object endObj = adapterPersistenceEncoding.getValue(nativeEndTimeHandler.getFieldName()); // visibility is unnecessary because this only happens after the geometry is read (its only used // in reconstructing common index values when using a secondary index) return new TimeRange(TimeUtils.getTimeMillis(startObj), TimeUtils.getTimeMillis(endObj), null); } }
@Override public synchronized TimeDescriptors getTimeDescriptors() { if (timeDescriptors == null) { timeDescriptors = TimeUtils.inferTimeAttributeDescriptor(persistedFeatureType); } return timeDescriptors; }
/** * Get the time in millis of this temporal object (either numeric interpreted as millisecond time * in GMT, Date, or Calendar) * * @param timeObj The temporal object * @return The time in milliseconds since the epoch in GMT */ public static long getTimeMillis(final Object timeObj) { // handle dates, calendars, and Numbers only if (timeObj != null) { if (timeObj instanceof Calendar) { return calendarToGMTMillis(((Calendar) timeObj)); } else if (timeObj instanceof Date) { return ((Date) timeObj).getTime(); } else if (timeObj instanceof Number) { return ((Number) timeObj).longValue(); } else { LOGGER.warn( "Time value '" + timeObj + "' of type '" + timeObj.getClass() + "' is not of expected temporal type"); } } return RESERVED_MILLIS_FOR_NULL; }
@Override protected Interval getInterval(final SimpleFeature entry) { if ((fieldNameParam != null) && !fieldNameParam.isEmpty()) { return TimeUtils.getInterval(entry, fieldNameParam.getFieldName()); desc = TimeUtils.inferTimeAttributeDescriptor(entry.getFeatureType()); descMap.put(type, desc); Instant.ofEpochMilli(TimeUtils.getTimeMillis(start)), Instant.ofEpochMilli(TimeUtils.getTimeMillis(end))); } else if (desc.getTime() != null) { final Object time = entry.getAttribute(desc.getTime().getName()); return null; final Instant instant = Instant.ofEpochMilli(TimeUtils.getTimeMillis(time)); return Interval.of(instant, instant);
if (useDuring) { timeConstraint = TimeUtils.toDuringFilter( startDate.getTime(), endDate.getTime(), } else { timeConstraint = TimeUtils.toFilter( startDate.getTime(), endDate.getTime(),
@Override public void updateType(final SimpleFeatureType persistType) { for (final AttributeDescriptor attrDesc : persistType.getAttributeDescriptors()) { final Class<?> bindingClass = attrDesc.getType().getBinding(); if (TimeUtils.isTemporal(bindingClass)) { attrDesc.getUserData().put("time", Boolean.FALSE); } } if (startRangeName != null) { persistType.getDescriptor(startRangeName).getUserData().put("start", Boolean.TRUE); } if (endRangeName != null) { persistType.getDescriptor(endRangeName).getUserData().put("end", Boolean.TRUE); } if (timeName != null) { persistType.getDescriptor(timeName).getUserData().put("time", Boolean.TRUE); } }
/** * Compose a time constraints. When the provided constraints do not fulfill the indexed * dimensions, compose constraints from statistics. * * @param featureType * @param timeDescriptors * @param statsMap * @param timeBoundsSet * @return */ public static Constraints composeTimeConstraints( final SimpleFeatureType featureType, final TimeDescriptors timeDescriptors, final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap, final TemporalConstraintsSet timeBoundsSet) { final TemporalConstraints timeBounds = TimeUtils.getTemporalConstraintsForDescriptors(timeDescriptors, timeBoundsSet); return (timeBounds != null) && !timeBounds.isEmpty() ? ExplicitSpatialTemporalQuery.createConstraints(timeBounds, false) : new Constraints(getTimeConstraintsFromIndex(timeDescriptors, statsMap)); }
@SuppressWarnings("unchecked") @Override public PersistentValue<Object>[] toNativeValues(final Time indexValue) { final NumericData value = indexValue.toNumericData(); final Class<?> startBindingClass = nativeStartTimeHandler.attrDesc.getType().getBinding(); final Object startObj = TimeUtils.getTimeValue(startBindingClass, (long) value.getMin()); final Class<?> endBindingClass = nativeEndTimeHandler.attrDesc.getType().getBinding(); final Object endObj = TimeUtils.getTimeValue(endBindingClass, (long) value.getMax()); return new PersistentValue[] { new PersistentValue<>(nativeStartTimeHandler.getFieldName(), startObj), new PersistentValue<>(nativeEndTimeHandler.getFieldName(), endObj),}; }
@Override protected Interval getInterval(final SimpleFeature entry) { return TimeUtils.getInterval(entry, getFieldName()); }
public static TemporalConstraints getTemporalConstraintsForDescriptors( final TimeDescriptors timeDescriptors, final TemporalConstraintsSet timeBoundsSet) { if ((timeBoundsSet == null) || timeBoundsSet.isEmpty()) { return new TemporalConstraints(); } if ((timeDescriptors.getStartRange() != null) && (timeDescriptors.getEndRange() != null)) { return composeRangeTemporalConstraints(timeDescriptors, timeBoundsSet); } else if ((timeDescriptors.getTime() != null) && timeBoundsSet.hasConstraintsFor(timeDescriptors.getTime().getLocalName())) { return timeBoundsSet.getConstraintsFor(timeDescriptors.getTime().getLocalName()); } return new TemporalConstraints(); }
protected static Filter getFilter( final GeotoolsFeatureDataAdapter adapter, final QueryConstraints delegateConstraints) { final List<MultiDimensionalNumericData> constraints = delegateConstraints.getIndexConstraints(new TemporalIndexBuilder().createIndex()); if (adapter.getTimeDescriptors().getTime() != null) { return constraintsToFilter( constraints, data -> TimeUtils.toDuringFilter( (long) data.getMinValuesPerDimension()[0], (long) data.getMaxValuesPerDimension()[0], adapter.getTimeDescriptors().getTime().getLocalName())); } else if ((adapter.getTimeDescriptors().getStartRange() != null) && (adapter.getTimeDescriptors().getEndRange() != null)) { return constraintsToFilter( constraints, data -> TimeUtils.toFilter( (long) data.getMinValuesPerDimension()[0], (long) data.getMaxValuesPerDimension()[0], adapter.getTimeDescriptors().getStartRange().getLocalName(), adapter.getTimeDescriptors().getEndRange().getLocalName())); } return null; }
for (final AttributeDescriptor attrDesc : persistType.getAttributeDescriptors()) { final Class<?> bindingClass = attrDesc.getType().getBinding(); if (TimeUtils.isTemporal(bindingClass)) { final Boolean isTime = (Boolean) attrDesc.getUserData().get("time"); if (isTime != null) {
/** * If composed constraints matched statistics constraints, are empty or null, then return empty * constraint set. * * @param featureType * @param timeDescriptors * @param statsMap * @param timeBoundsSet * @return */ public static Constraints composeTimeBoundedConstraints( final SimpleFeatureType featureType, final TimeDescriptors timeDescriptors, final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap, final TemporalConstraintsSet timeBoundsSet) { if ((timeBoundsSet == null) || timeBoundsSet.isEmpty() || !timeDescriptors.hasTime()) { return new Constraints(); } final TemporalConstraints boundsTemporalConstraints = TimeUtils.getTemporalConstraintsForDescriptors(timeDescriptors, timeBoundsSet); if (boundsTemporalConstraints.isEmpty()) { return new Constraints(); } final Constraints indexTimeConstraints = new Constraints(QueryIndexHelper.getTimeConstraintsFromIndex(timeDescriptors, statsMap)); final Constraints boundsTimeConstraints = ExplicitSpatialTemporalQuery.createConstraints(boundsTemporalConstraints, false); return (boundsTimeConstraints.matches(indexTimeConstraints)) ? new Constraints() : boundsTimeConstraints; }
@SuppressWarnings("unchecked") @Override public PersistentValue<Object>[] toNativeValues(final Time indexValue) { final Class<?> bindingClass = nativeTimestampHandler.attrDesc.getType().getBinding(); final Object obj = TimeUtils.getTimeValue(bindingClass, (long) indexValue.toNumericData().getCentroid()); return new PersistentValue[] { new PersistentValue<>(nativeTimestampHandler.getFieldName(), obj)}; }
@Override public Time toIndexValue(final PersistentDataset<Object> adapterPersistenceEncoding) { final Object object = adapterPersistenceEncoding.getValue(nativeTimestampHandler.getFieldName()); // visibility is unnecessary because this only happens after the geometry is read (its only used // in reconstructing common index values when using a secondary index) return new Timestamp(TimeUtils.getTimeMillis(object), null); } }
if (TimeUtils.isTemporal(descriptor.getType().getBinding())) {
public synchronized void resetTimeDescriptors() { timeDescriptors = TimeUtils.inferTimeAttributeDescriptor(persistedFeatureType); }
TimeUtils.getTemporalConstraintsForDescriptors( adapter.getTimeDescriptors(), timeConstraintSet); TimeUtils.getTemporalConstraintsForDescriptors( adapter.getTimeDescriptors(), timeConstraintSet);
@Override public byte[] writeField(final Calendar cal) { if (cal == null) { return new byte[] {}; } long time = TimeUtils.calendarToGMTMillis(cal); final ByteBuffer buf = ByteBuffer.allocate(VarintUtils.timeByteLength(time)); VarintUtils.writeTime(time, buf); return buf.array(); } }
return new Timestamp(TimeUtils.getTimeMillis(endObj), visibility); return new Timestamp(TimeUtils.getTimeMillis(startObj), visibility); TimeUtils.getTimeMillis(startObj), TimeUtils.getTimeMillis(endObj), visibility);