Search in sources :

Example 1 with ConstraintsByClass

use of org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass in project geowave by locationtech.

the class ChooseLocalityPreservingQueryStrategyTest method createConstraints.

private ConstraintsByClass createConstraints(final double lat, final double lon, final double time) {
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(LatitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0, lat), true));
    cs1.addConstraint(LongitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0, lon), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(TimeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0, time), true));
    return new ConstraintsByClass(Arrays.asList(cs2a)).merge(Collections.singletonList(cs1));
}
Also used : ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet)

Example 2 with ConstraintsByClass

use of org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass in project geowave by locationtech.

the class GeometryUtils method basicGeoConstraintsWrapperFromGeometry.

/**
 * This utility method will convert a JTS geometry to contraints that can be used in a GeoWave
 * query.
 *
 * @return Constraints as a mapping of NumericData objects representing ranges for a latitude
 *         dimension and a longitude dimension
 */
public static GeoConstraintsWrapper basicGeoConstraintsWrapperFromGeometry(final Geometry geometry) {
    final List<ConstraintSet> set = new LinkedList<>();
    final boolean geometryConstraintsExactMatch = constructListOfConstraintSetsFromGeometry(geometry, set, true);
    return new GeoConstraintsWrapper(new ConstraintsByClass(set), geometryConstraintsExactMatch, geometry);
}
Also used : ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) LinkedList(java.util.LinkedList)

Example 3 with ConstraintsByClass

use of org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass in project geowave by locationtech.

the class BasicQueryByClassTest method testIntersectCasesWithPersistence.

@Test
public void testIntersectCasesWithPersistence() {
    final Index index = new CustomNameIndex(new ExampleNumericIndexStrategy(), new BasicIndexModel(new NumericDimensionField[] { new ExampleDimensionOne(), new ExampleDimensionTwo() }), "22");
    final List<MultiDimensionalNumericData> expectedResults = new ArrayList<>();
    expectedResults.add(new BasicNumericDataset(new NumericData[] { new ConstrainedIndexValue(0.3, 0.5), new ConstrainedIndexValue(0.1, 0.7) }));
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(ExampleDimensionOne.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
    cs1.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(0.4, 0.7), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(0.1, 0.2), true));
    final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a)).merge(Collections.singletonList(cs1));
    assertEquals(expectedResults, constraints.getIndexConstraints(new IndexImpl(new ExampleNumericIndexStrategy(), null)));
    final byte[] image = new BasicQueryByClass(constraints).toBinary();
    final BasicQueryByClass query = new BasicQueryByClass();
    query.fromBinary(image);
    assertEquals(expectedResults, query.getIndexConstraints(index));
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) ArrayList(java.util.ArrayList) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) Index(org.locationtech.geowave.core.store.api.Index) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) Test(org.junit.Test)

Example 4 with ConstraintsByClass

use of org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass in project geowave by locationtech.

the class BasicQueryByClassTest method testDisjointCasesWithPersistence.

@Test
public void testDisjointCasesWithPersistence() {
    final List<MultiDimensionalNumericData> expectedResults = new ArrayList<>();
    expectedResults.add(new BasicNumericDataset(new NumericData[] { new ConstrainedIndexValue(0.3, 0.7), new ConstrainedIndexValue(0.1, 2.3) }));
    expectedResults.add(new BasicNumericDataset(new NumericData[] { new ConstrainedIndexValue(0.3, 0.7), new ConstrainedIndexValue(3.4, 3.7) }));
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(ExampleDimensionOne.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
    cs1.addConstraint(ExampleDimensionOne.class, new ConstraintData(new ConstrainedIndexValue(0.4, 0.7), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(0.1, 0.2), true));
    cs2a.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(2.1, 2.3), true));
    final ConstraintSet cs2b = new ConstraintSet();
    cs2b.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(3.4, 3.7), true));
    final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a, cs2b)).merge(Collections.singletonList(cs1));
    assertEquals(expectedResults, constraints.getIndexConstraints(new IndexImpl(new ExampleNumericIndexStrategy(), null)));
    final byte[] image = new BasicQueryByClass(constraints).toBinary();
    final BasicQueryByClass query = new BasicQueryByClass();
    query.fromBinary(image);
    final Index index = new CustomNameIndex(new ExampleNumericIndexStrategy(), new BasicIndexModel(new NumericDimensionField[] { new ExampleDimensionOne(), new ExampleDimensionTwo() }), "22");
    assertEquals(expectedResults, query.getIndexConstraints(index));
    final List<QueryFilter> filters = query.createFilters(index);
    assertEquals(1, filters.size());
    final Map<String, ConstrainedIndexValue> fieldIdToValueMap = new HashMap<>();
    fieldIdToValueMap.put("one", new ConstrainedIndexValue(0.4, 0.4));
    fieldIdToValueMap.put("two", new ConstrainedIndexValue(0.5, 0.5));
    final CommonIndexModel model = null;
    assertTrue(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
    1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
    fieldIdToValueMap.put("one", new ConstrainedIndexValue(0.1, 0.1));
    assertFalse(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
    1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
    fieldIdToValueMap.put("one", new ConstrainedIndexValue(0.4, 0.4));
    fieldIdToValueMap.put("two", new ConstrainedIndexValue(5.0, 5.0));
    assertFalse(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
    1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
    /**
     * Tests the 'OR' Case
     */
    fieldIdToValueMap.put("two", new ConstrainedIndexValue(3.5, 3.5));
    assertTrue(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
    1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) HashMap(java.util.HashMap) CommonIndexedPersistenceEncoding(org.locationtech.geowave.core.store.data.CommonIndexedPersistenceEncoding) ArrayList(java.util.ArrayList) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) Index(org.locationtech.geowave.core.store.api.Index) CommonIndexModel(org.locationtech.geowave.core.store.index.CommonIndexModel) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) MultiFieldPersistentDataset(org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) Test(org.junit.Test)

Example 5 with ConstraintsByClass

use of org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass in project geowave by locationtech.

the class QueryIndexHelper method composeConstraints.

/**
 * Compose a query from the set of constraints. When the provided constraints do not fulfill the
 * indexed dimensions, compose constraints from statistics.
 */
public static ConstraintsByClass composeConstraints(final StatisticsCache statisticsCache, final SimpleFeatureType featureType, final TimeDescriptors timeDescriptors, final Geometry jtsBounds, final TemporalConstraintsSet timeBoundsSet) {
    final ConstraintsByClass timeConstraints = composeTimeConstraints(statisticsCache, featureType, timeDescriptors, timeBoundsSet);
    final GeoConstraintsWrapper geoConstraints = composeGeometricConstraints(featureType, jtsBounds);
    return timeConstraints.merge(geoConstraints.getConstraints());
}
Also used : ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) GeoConstraintsWrapper(org.locationtech.geowave.core.geotime.util.GeometryUtils.GeoConstraintsWrapper)

Aggregations

ConstraintsByClass (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass)11 ConstraintSet (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet)7 ConstraintData (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData)6 BasicQueryByClass (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass)5 Index (org.locationtech.geowave.core.store.api.Index)4 Test (org.junit.Test)3 GeoConstraintsWrapper (org.locationtech.geowave.core.geotime.util.GeometryUtils.GeoConstraintsWrapper)3 BasicNumericDataset (org.locationtech.geowave.core.index.numeric.BasicNumericDataset)3 NumericData (org.locationtech.geowave.core.index.numeric.NumericData)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)2 CommonIndexedPersistenceEncoding (org.locationtech.geowave.core.store.data.CommonIndexedPersistenceEncoding)2 NumericDimensionField (org.locationtech.geowave.core.store.dimension.NumericDimensionField)2 BasicIndexModel (org.locationtech.geowave.core.store.index.BasicIndexModel)2 CustomNameIndex (org.locationtech.geowave.core.store.index.CustomNameIndex)2 IndexImpl (org.locationtech.geowave.core.store.index.IndexImpl)2 QueryFilter (org.locationtech.geowave.core.store.query.filter.QueryFilter)2 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1