public TemporalConstraintsSet getConstraints(final Filter filter) { final TemporalConstraintsSet constrainsSet = getRawConstraints(filter); constrainsSet.setExact(!approximation); for (final String[] range : validParamRanges) { if (constrainsSet.hasConstraintsFor(range[0]) || constrainsSet.hasConstraintsFor(range[1])) { final TemporalConstraints start = (constrainsSet.hasConstraintsFor(range[0])) ? constrainsSet.getConstraintsFor(range[0]) : constrainsSet.getConstraintsFor(range[1]); // Note: getConstraints has a side effect that is returns a // constraint--full range, if necessary // so if start and end are both not specific, the prior line // would create the end // thus sconstraints and econstraints will be identical final TemporalConstraints end = (constrainsSet.hasConstraintsFor(range[1])) ? constrainsSet.getConstraintsFor(range[1]) : start; constrainsSet.removeConstraints(range[0], range[1]); final TemporalConstraints constraintsForRange = constrainsSet.getConstraintsForRange(range[0], range[1]); constraintsForRange.replaceWithIntersections( new TemporalConstraints( new TemporalRange( start.getStartRange().getStartTime(), end.getEndRange().getEndTime()), constraintsForRange.getName())); } } return constrainsSet; }
@Override public Object visit(final Or filter, final Object data) { final TemporalConstraintsSet constraints = new TemporalConstraintsSet(); for (final Filter f : filter.getChildren()) { final Object output = f.accept(this, data); if (output instanceof ParameterTimeConstraint) { final ParameterTimeConstraint ranges = (ParameterTimeConstraint) output; constraints.getConstraintsFor(ranges.getName()).replaceWithMerged(ranges); } else if (output instanceof TemporalConstraintsSet) { final TemporalConstraintsSet rangeSet = (TemporalConstraintsSet) output; for (final Map.Entry<String, TemporalConstraints> entry : rangeSet.getSet()) { constraints.getConstraintsFor(entry.getKey()).replaceWithMerged(entry.getValue()); } } } return constraints; }
private TemporalConstraintsSet getRawConstraints(final Filter filter) { final Object output = filter.accept(this, null); if (output instanceof TemporalConstraintsSet) { return (TemporalConstraintsSet) output; } else if (output instanceof ParameterTimeConstraint) { final ParameterTimeConstraint paramConstraint = (ParameterTimeConstraint) output; final TemporalConstraintsSet constraintSet = new TemporalConstraintsSet(); constraintSet.getConstraintsFor(paramConstraint.getName()).replaceWithMerged(paramConstraint); return constraintSet; } return new TemporalConstraintsSet(); }
/** * Compose temporal constraints given the constraint set and the descriptors for the index. * * @param timeDescriptors * @param constraintsSet * @return null if the constraints does not have the fields required by the time descriptors */ public static TemporalConstraints composeRangeTemporalConstraints( final TimeDescriptors timeDescriptors, final TemporalConstraintsSet constraintsSet) { if ((timeDescriptors.getEndRange() != null) && (timeDescriptors.getStartRange() != null)) { final String ename = timeDescriptors.getEndRange().getLocalName(); final String sname = timeDescriptors.getStartRange().getLocalName(); if (constraintsSet.hasConstraintsForRange(sname, ename)) { return constraintsSet.getConstraintsForRange(sname, ename); } } else if ((timeDescriptors.getTime() != null) && constraintsSet.hasConstraintsFor(timeDescriptors.getTime().getLocalName())) { return constraintsSet.getConstraintsFor(timeDescriptors.getTime().getLocalName()); } return new TemporalConstraints(); }
@Override public Object visit(final And filter, final Object data) { final TemporalConstraintsSet constraints = new TemporalConstraintsSet(); for (final Filter f : filter.getChildren()) { final Object output = f.accept(this, data); if (output instanceof ParameterTimeConstraint) { final ParameterTimeConstraint ranges = (ParameterTimeConstraint) output; constraints.getConstraintsFor(ranges.getName()).replaceWithIntersections(ranges); } else if (output instanceof TemporalConstraintsSet) { final TemporalConstraintsSet rangeSet = (TemporalConstraintsSet) output; for (final Map.Entry<String, TemporalConstraints> entry : rangeSet.getSet()) { constraints.getConstraintsFor(entry.getKey()).replaceWithIntersections(entry.getValue()); if (constraints.hasConstraintsFor(range[0]) && constraints.hasConstraintsFor(range[1])) { final TemporalConstraints start = constraints.getConstraintsFor(range[0]); final TemporalConstraints end = constraints.getConstraintsFor(range[1]); constraints.removeConstraints(range[0], range[1]); constraints.getConstraintsForRange(range[0], range[1]).add( new TemporalRange( end.getStartRange().getStartTime(), constraints.getConstraintsForRange(range[0], range[1]).add( new TemporalRange( start.getStartRange().getStartTime(),
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(); }
/** * Return constraints that are indexed * * @param query * @return */ protected TemporalConstraintsSet getBoundedTime(final Query query) { if (query == null) { return null; } final TemporalConstraintsSet constraints = new ExtractTimeFilterVisitor( reader.getComponents().getAdapter().getTimeDescriptors()).getConstraints(query); return constraints.isEmpty() ? constraints : reader.clipIndexedTemporalConstraints(constraints); }
public boolean isEmpty() { if (constraintsSet.isEmpty()) { return true; } boolean isEmpty = true; for (final Entry<String, TemporalConstraints> entry : getSet()) { isEmpty &= entry.getValue().isEmpty(); } return isEmpty; } }
private BasicQuery getQuery( final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap, final Geometry jtsBounds, final TemporalConstraintsSet timeBounds) { final Constraints timeConstraints = QueryIndexHelper.composeTimeBoundedConstraints( components.getAdapter().getFeatureType(), components.getAdapter().getTimeDescriptors(), statsMap, timeBounds); final GeoConstraintsWrapper geoConstraints = QueryIndexHelper.composeGeometricConstraints(getFeatureType(), statsMap, jtsBounds); /** * NOTE: query to an index that requires a constraint and the constraint is missing equates to a * full table scan. @see BasicQuery */ final BasicQuery query = composeQuery(geoConstraints, timeConstraints); query.setExact(timeBounds.isExact()); return query; }
final String ename = timeDescriptors.getEndRange().getLocalName(); final String sname = timeDescriptors.getStartRange().getLocalName(); if (constraintsSet.hasConstraintsForRange(sname, ename)) { final TemporalRange statsStartRange = getStatsRange(statsMap, timeDescriptors.getStartRange()); new TemporalRange(statsStartRange.getStartTime(), statsEndRange.getEndTime()); final TemporalConstraints constraints = constraintsSet.getConstraintsForRange(sname, ename); constraints.replaceWithIntersections( new TemporalConstraints(fullRange, constraints.getName())); constraintsSet.removeAllConstraintsExcept(constraints.getName()); && constraintsSet.hasConstraintsFor(timeDescriptors.getTime().getLocalName())) { final String name = timeDescriptors.getTime().getLocalName(); final FeatureTimeRangeStatistics stats = name).build().getId())); final TemporalConstraints constraints = constraintsSet.getConstraintsFor(name); if (stats != null) { constraints.replaceWithIntersections( new TemporalConstraints(stats.asTemporalRange(), name)); constraintsSet.removeAllConstraintsExcept(name); return constraintsSet;
/** * 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; }
@Override public Object visit(final Not filter, final Object data) { final Object output = filter.getFilter().accept(this, data); if (output instanceof ParameterTimeConstraint) { return not((ParameterTimeConstraint) output); } else if (output instanceof TemporalConstraintsSet) { final TemporalConstraintsSet newRangeSet = new TemporalConstraintsSet(); final TemporalConstraintsSet rangeSet = (TemporalConstraintsSet) output; for (final Map.Entry<String, TemporalConstraints> entry : rangeSet.getSet()) { newRangeSet.getConstraintsFor(entry.getKey()).replaceWithMerged(not(entry.getValue())); } return newRangeSet; } return output; }