Skip to content

Commit

Permalink
Query constraints using ordered dimensions (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfecher authored May 2, 2019
1 parent ecea4c4 commit 4f39304
Show file tree
Hide file tree
Showing 40 changed files with 1,287 additions and 721 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.locationtech.geowave.core.store.api.Index;
import org.locationtech.geowave.core.store.dimension.NumericDimensionField;
import org.locationtech.geowave.core.store.index.CommonIndexModel;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass;
import org.locationtech.geowave.core.store.query.filter.BasicQueryFilter.BasicQueryCompareOperation;
import org.locationtech.geowave.core.store.query.filter.QueryFilter;
import org.locationtech.jts.geom.Geometry;
Expand All @@ -43,7 +43,7 @@
* The Spatial Query class represents a query in two dimensions. The constraint that is applied
* represents an intersection operation on the query geometry.
*/
public class ExplicitSpatialQuery extends BasicQuery {
public class ExplicitSpatialQuery extends BasicQueryByClass {
private static final Logger LOGGER = LoggerFactory.getLogger(ExplicitSpatialQuery.class);

private static class CrsCache {
Expand Down Expand Up @@ -75,12 +75,12 @@ public ExplicitSpatialQuery(final Geometry queryGeometry) {
this(GeometryUtils.basicConstraintsFromGeometry(queryGeometry), queryGeometry);
}

public ExplicitSpatialQuery(final Constraints constraints, final Geometry queryGeometry) {
public ExplicitSpatialQuery(final ConstraintsByClass constraints, final Geometry queryGeometry) {
this(constraints, queryGeometry, (String) null);
}

public ExplicitSpatialQuery(
final Constraints constraints,
final ConstraintsByClass constraints,
final Geometry queryGeometry,
final String crsCode) {
this(
Expand Down Expand Up @@ -121,7 +121,7 @@ public ExplicitSpatialQuery(final Geometry queryGeometry, final CompareOperation
* @param compareOp predicate associated query geometry
*/
public ExplicitSpatialQuery(
final Constraints constraints,
final ConstraintsByClass constraints,
final Geometry queryGeometry,
final CompareOperation compareOp) {
this(constraints, queryGeometry, compareOp, BasicQueryCompareOperation.INTERSECTS);
Expand Down Expand Up @@ -149,7 +149,7 @@ public ExplicitSpatialQuery(
* @param nonSpatialCompareOp predicate associated non-spatial fields (i.e Time)
*/
public ExplicitSpatialQuery(
final Constraints constraints,
final ConstraintsByClass constraints,
final Geometry queryGeometry,
final CompareOperation compareOp,
final BasicQueryCompareOperation nonSpatialCompareOp) {
Expand All @@ -162,7 +162,7 @@ public ExplicitSpatialQuery(
}

public ExplicitSpatialQuery(
final Constraints constraints,
final ConstraintsByClass constraints,
final Geometry queryGeometry,
final String crsCode,
final CompareOperation compareOp,
Expand Down Expand Up @@ -281,8 +281,7 @@ private CrsCache transformToIndex(final String indexCrsStr, final Index index) {
private static List<MultiDimensionalNumericData> indexConstraintsFromGeometry(
final Geometry geom,
final Index index) {
return GeometryUtils.basicConstraintsFromGeometry(geom).getIndexConstraints(
index.getIndexStrategy());
return GeometryUtils.basicConstraintsFromGeometry(geom).getIndexConstraints(index);
}

private static String getCrs(final CommonIndexModel indexModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static ConstraintSet createConstraints(
isDefault));
}

public static Constraints createConstraints(
public static ConstraintsByClass createConstraints(
final TemporalConstraints temporalConstraints,
final boolean isDefault) {
final List<ConstraintSet> constraints = new ArrayList<>();
Expand All @@ -135,10 +135,12 @@ public static Constraints createConstraints(
new NumericRange(range.getStartTime().getTime(), range.getEndTime().getTime()),
isDefault)));
}
return new Constraints(constraints);
return new ConstraintsByClass(constraints);
}

public static Constraints createConstraints(final Interval[] intervals, final boolean isDefault) {
public static ConstraintsByClass createConstraints(
final Interval[] intervals,
final boolean isDefault) {
final List<ConstraintSet> constraints = new ArrayList<>();
for (final Interval range : intervals) {
constraints.add(
Expand All @@ -152,7 +154,7 @@ public static Constraints createConstraints(final Interval[] intervals, final bo
Math.max(range.getEnd().toEpochMilli() - 1, range.getStart().toEpochMilli())),
isDefault)));
}
return new Constraints(constraints);
return new ConstraintsByClass(constraints);
}

/**
Expand All @@ -164,11 +166,12 @@ public static Constraints createConstraints(final Interval[] intervals, final bo
* @param queryGeometry
* @return
*/
private static Constraints createSpatialTemporalConstraints(
private static ConstraintsByClass createSpatialTemporalConstraints(
final TemporalConstraints temporalConstraints,
final Geometry queryGeometry) {
final Constraints geoConstraints = GeometryUtils.basicConstraintsFromGeometry(queryGeometry);
final Constraints timeConstraints = createConstraints(temporalConstraints, false);
final ConstraintsByClass geoConstraints =
GeometryUtils.basicConstraintsFromGeometry(queryGeometry);
final ConstraintsByClass timeConstraints = createConstraints(temporalConstraints, false);
return geoConstraints.merge(timeConstraints);
}

Expand All @@ -181,11 +184,12 @@ private static Constraints createSpatialTemporalConstraints(
* @param queryGeometry
* @return
*/
private static Constraints createSpatialTemporalConstraints(
private static ConstraintsByClass createSpatialTemporalConstraints(
final Interval[] intervals,
final Geometry queryGeometry) {
final Constraints geoConstraints = GeometryUtils.basicConstraintsFromGeometry(queryGeometry);
final Constraints timeConstraints = createConstraints(intervals, false);
final ConstraintsByClass geoConstraints =
GeometryUtils.basicConstraintsFromGeometry(queryGeometry);
final ConstraintsByClass timeConstraints = createConstraints(intervals, false);
return geoConstraints.merge(timeConstraints);
}

Expand All @@ -197,13 +201,14 @@ private static Constraints createSpatialTemporalConstraints(
* @param queryGeometry
* @return
*/
private static Constraints createSpatialTemporalConstraints(
private static ConstraintsByClass createSpatialTemporalConstraints(
final Date startTime,
final Date endTime,
final Geometry queryGeometry) {
final Constraints geoConstraints = GeometryUtils.basicConstraintsFromGeometry(queryGeometry);
final ConstraintsByClass geoConstraints =
GeometryUtils.basicConstraintsFromGeometry(queryGeometry);
return geoConstraints.merge(
new Constraints(
new ConstraintsByClass(
new ConstraintSet(
TimeDefinition.class,
new ConstraintData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import java.util.List;
import org.locationtech.geowave.core.geotime.index.dimension.TimeDefinition;
import org.locationtech.geowave.core.index.sfc.data.NumericRange;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass;
import org.threeten.extra.Interval;

/**
* The Spatial Temporal Query class represents a query in three dimensions. The constraint that is
* applied represents an intersection operation on the query geometry AND a date range intersection
* based on startTime and endTime.
*/
public class ExplicitTemporalQuery extends BasicQuery {
public class ExplicitTemporalQuery extends BasicQueryByClass {
public ExplicitTemporalQuery(final Interval[] intervals) {
super(createTemporalConstraints(intervals));
}
Expand All @@ -33,7 +33,7 @@ public ExplicitTemporalQuery() {
super();
}

private static Constraints createTemporalConstraints(
private static ConstraintsByClass createTemporalConstraints(
final TemporalConstraints temporalConstraints) {
final List<ConstraintSet> constraints = new ArrayList<>();
for (final TemporalRange range : temporalConstraints.getRanges()) {
Expand All @@ -44,10 +44,10 @@ private static Constraints createTemporalConstraints(
new NumericRange(range.getStartTime().getTime(), range.getEndTime().getTime()),
false)));
}
return new Constraints(constraints);
return new ConstraintsByClass(constraints);
}

private static Constraints createTemporalConstraints(final Interval[] intervals) {
private static ConstraintsByClass createTemporalConstraints(final Interval[] intervals) {
final List<ConstraintSet> constraints = new ArrayList<>();
for (final Interval range : intervals) {
constraints.add(
Expand All @@ -61,6 +61,6 @@ private static Constraints createTemporalConstraints(final Interval[] intervals)
Math.max(range.getEnd().toEpochMilli() - 1, range.getStart().toEpochMilli())),
false)));
}
return new Constraints(constraints);
return new ConstraintsByClass(constraints);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public IndexOnlySpatialQuery() {
super();
}

public IndexOnlySpatialQuery(final Constraints constraints, final Geometry queryGeometry) {
public IndexOnlySpatialQuery(final ConstraintsByClass constraints, final Geometry queryGeometry) {
super(constraints, queryGeometry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.locationtech.geowave.core.store.api.DataTypeAdapter;
import org.locationtech.geowave.core.store.api.Index;
import org.locationtech.geowave.core.store.query.constraints.AdapterAndIndexBasedQueryConstraints;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.Constraints;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass;
import org.locationtech.geowave.core.store.query.constraints.QueryConstraints;
import org.locationtech.geowave.core.store.query.filter.BasicQueryFilter.BasicQueryCompareOperation;
import org.locationtech.jts.geom.Geometry;
Expand All @@ -53,7 +53,7 @@ public static QueryConstraints createOptimalQuery(
final String cql,
final GeotoolsFeatureDataAdapter adapter,
final Index index,
final BasicQuery baseQuery) throws CQLException {
final BasicQueryByClass baseQuery) throws CQLException {
return createOptimalQuery(cql, adapter, CompareOperation.INTERSECTS, index, baseQuery);
}

Expand All @@ -62,7 +62,7 @@ public static QueryConstraints createOptimalQuery(
final GeotoolsFeatureDataAdapter adapter,
final CompareOperation geoCompareOp,
final Index index,
final BasicQuery baseQuery) throws CQLException {
final BasicQueryByClass baseQuery) throws CQLException {
final Filter cqlFilter = CQL.toFilter(cql);
return createOptimalQuery(cqlFilter, adapter, geoCompareOp, index, baseQuery);
}
Expand All @@ -78,7 +78,7 @@ public static QueryConstraints createOptimalQuery(
final Filter cqlFilter,
final GeotoolsFeatureDataAdapter adapter,
final Index index,
final BasicQuery baseQuery) {
final BasicQueryByClass baseQuery) {
return createOptimalQuery(cqlFilter, adapter, CompareOperation.INTERSECTS, index, baseQuery);
}

Expand All @@ -87,7 +87,7 @@ public static QueryConstraints createOptimalQuery(
final GeotoolsFeatureDataAdapter adapter,
final CompareOperation geoCompareOp,
final Index index,
BasicQuery baseQuery) {
BasicQueryByClass baseQuery) {
final ExtractAttributesFilter attributesVisitor = new ExtractAttributesFilter();

final Object obj = cqlFilter.accept(attributesVisitor, null);
Expand Down Expand Up @@ -138,7 +138,7 @@ public static QueryConstraints createOptimalQuery(
final GeoConstraintsWrapper geoConstraints =
GeometryUtils.basicGeoConstraintsWrapperFromGeometry(geometry);

Constraints constraints = geoConstraints.getConstraints();
ConstraintsByClass constraints = geoConstraints.getConstraints();
final CompareOperation extractedCompareOp = geometryAndCompareOp.getCompareOp();
if ((timeConstraintSet != null) && !timeConstraintSet.isEmpty()) {
// determine which time constraints are associated with an
Expand All @@ -149,7 +149,7 @@ public static QueryConstraints createOptimalQuery(
adapter.getTimeDescriptors(),
timeConstraintSet);
// convert to constraints
final Constraints timeConstraints =
final ConstraintsByClass timeConstraints =
ExplicitSpatialTemporalQuery.createConstraints(temporalConstraints, false);
constraints = geoConstraints.getConstraints().merge(timeConstraints);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ public void fromBinary(final byte[] bytes) {
*/
public static class GeometryImage {

byte[] geometryBinary;
PreparedGeometry preparedGeometry = null;
public byte[] geometryBinary;
public PreparedGeometry preparedGeometry = null;

public GeometryImage(final PreparedGeometry preparedGeometry) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.locationtech.geowave.core.store.adapter.statistics.StatisticsType;
import org.locationtech.geowave.core.store.api.StatisticsQueryBuilder;
import org.locationtech.geowave.core.store.entities.GeoWaveRow;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.ConstraintData;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.ConstraintSet;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet;
import org.locationtech.jts.geom.Envelope;

public abstract class BoundingBoxDataStatistics<T, B extends StatisticsQueryBuilder<Envelope, B>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
import org.locationtech.geowave.core.index.sfc.data.NumericValue;
import org.locationtech.geowave.core.store.api.Index;
import org.locationtech.geowave.core.store.data.field.FieldUtils;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.ConstraintData;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.ConstraintSet;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.Constraints;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass;
import org.locationtech.geowave.core.store.query.constraints.Constraints;
import org.locationtech.geowave.core.store.util.ClasspathUtils;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
Expand Down Expand Up @@ -147,12 +148,12 @@ public static void initClassLoader() throws MalformedURLException {
}
}

public static Constraints basicConstraintsFromGeometry(final Geometry geometry) {
public static ConstraintsByClass basicConstraintsFromGeometry(final Geometry geometry) {

final List<ConstraintSet> set = new LinkedList<>();
constructListOfConstraintSetsFromGeometry(geometry, set, false);

return new Constraints(set);
return new ConstraintsByClass(set);
}

/**
Expand All @@ -169,7 +170,10 @@ public static GeoConstraintsWrapper basicGeoConstraintsWrapperFromGeometry(
final boolean geometryConstraintsExactMatch =
constructListOfConstraintSetsFromGeometry(geometry, set, true);

return new GeoConstraintsWrapper(new Constraints(set), geometryConstraintsExactMatch, geometry);
return new GeoConstraintsWrapper(
new ConstraintsByClass(set),
geometryConstraintsExactMatch,
geometry);
}

/**
Expand Down Expand Up @@ -243,7 +247,7 @@ public static ConstraintSet basicConstraintSetFromEnvelope(final Envelope env) {
*/
public static Constraints basicConstraintsFromEnvelope(final Envelope env) {

return new Constraints(basicConstraintSetFromEnvelope(env));
return new ConstraintsByClass(basicConstraintSetFromEnvelope(env));
}

/**
Expand Down Expand Up @@ -385,20 +389,20 @@ public static Geometry infinity() {
}

public static class GeoConstraintsWrapper {
private final Constraints constraints;
private final ConstraintsByClass constraints;
private final boolean constraintsMatchGeometry;
private final Geometry jtsBounds;

public GeoConstraintsWrapper(
final Constraints constraints,
final ConstraintsByClass constraints,
final boolean constraintsMatchGeometry,
final Geometry jtsBounds) {
this.constraints = constraints;
this.constraintsMatchGeometry = constraintsMatchGeometry;
this.jtsBounds = jtsBounds;
}

public Constraints getConstraints() {
public ConstraintsByClass getConstraints() {
return constraints;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset;
import org.locationtech.geowave.core.store.data.PersistentDataset;
import org.locationtech.geowave.core.store.index.CommonIndexValue;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.ConstraintData;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.ConstraintSet;
import org.locationtech.geowave.core.store.query.constraints.BasicQuery.Constraints;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet;
import org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass;
import org.locationtech.geowave.core.store.query.filter.BasicQueryFilter.BasicQueryCompareOperation;
import org.locationtech.geowave.core.store.query.filter.QueryFilter;

Expand Down Expand Up @@ -64,9 +64,9 @@ public void performOp(final BasicQueryCompareOperation op, final boolean[] expec
df.parse("2017-02-22T12:00:00GMT-00:00").getTime(),
df.parse("2017-02-22T13:00:00GMT-00:00").getTime()),
true);
Constraints constaints =
new Constraints(new ConstraintSet(TimeDefinition.class, constrainData));
final BasicQuery query = new BasicQuery(constaints, op);
ConstraintsByClass constaints =
new ConstraintsByClass(new ConstraintSet(TimeDefinition.class, constrainData));
final BasicQueryByClass query = new BasicQueryByClass(constaints, op);

final CommonIndexedPersistenceEncoding[] data =
new CommonIndexedPersistenceEncoding[] {
Expand Down
Loading

0 comments on commit 4f39304

Please sign in to comment.