Search in sources :

Example 1 with SimpleNumericQuery

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

the class SimpleQuerySecondaryIndexIT method testMultipleSecondaryIndices.

// @Test
public void testMultipleSecondaryIndices() {
    final DataStore ds = dataStoreOptions.createDataStore();
    final SimpleFeatureType sft = SimpleIngest.createPointFeatureType();
    final GeotoolsFeatureDataAdapter fda = SimpleIngest.createDataAdapter(sft);
    final List<SimpleFeature> features = SimpleIngest.getGriddedFeatures(new SimpleFeatureBuilder(sft), 1234);
    final Index latIdx = new CustomNameIndex(new SimpleDoubleIndexStrategy(), new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>("Latitude", Double.class) }), "Lat_IDX");
    final Index lonIdx = new CustomNameIndex(new SimpleDoubleIndexStrategy(), new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>("Longitude", Double.class) }), "Lon_IDX");
    ds.addType(fda, TestUtils.DEFAULT_SPATIAL_INDEX, latIdx, lonIdx);
    int ingestedFeatures = 0;
    try (Writer<SimpleFeature> writer = ds.createWriter(fda.getTypeName())) {
        for (final SimpleFeature feat : features) {
            ingestedFeatures++;
            if ((ingestedFeatures % 5) == 0) {
                // just write 20 percent of the grid
                writer.write(feat);
            }
        }
    }
    try (CloseableIterator<SimpleFeature> it = ds.query(VectorQueryBuilder.newBuilder().indexName("Lon_IDX").addTypeName(sft.getTypeName()).constraints(new SimpleNumericQuery(Range.between((double) 0, (double) 0))).build())) {
        int count = 0;
        while (it.hasNext()) {
            it.next();
            count++;
        }
        Assert.assertTrue(count > 1);
    }
    Assert.assertTrue(ds.delete(VectorQueryBuilder.newBuilder().indexName("Lon_IDX").addTypeName(sft.getTypeName()).constraints(new SimpleNumericQuery(Range.between((double) 0, (double) 0))).build()));
    try (CloseableIterator<SimpleFeature> it = ds.query(VectorQueryBuilder.newBuilder().indexName("Lon_IDX").addTypeName(sft.getTypeName()).constraints(new SimpleNumericQuery(Range.between((double) 0, (double) 0))).build())) {
        int count = 0;
        while (it.hasNext()) {
            it.next();
            count++;
        }
        Assert.assertTrue(count == 0);
    }
    try (CloseableIterator<SimpleFeature> it = ds.query(VectorQueryBuilder.newBuilder().indexName("Lon_IDX").addTypeName(sft.getTypeName()).constraints(new SimpleNumericQuery(Range.between((double) 1, (double) 45))).build())) {
        int count = 0;
        while (it.hasNext()) {
            it.next();
            count++;
        }
        Assert.assertTrue(count > 1);
    }
    ds.deleteAll();
}
Also used : BasicNumericDimensionField(org.locationtech.geowave.core.store.dimension.BasicNumericDimensionField) NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) BasicNumericDimensionField(org.locationtech.geowave.core.store.dimension.BasicNumericDimensionField) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) Index(org.locationtech.geowave.core.store.api.Index) SimpleFeature(org.opengis.feature.simple.SimpleFeature) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) DataStore(org.locationtech.geowave.core.store.api.DataStore) SimpleDoubleIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleDoubleIndexStrategy) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) SimpleNumericQuery(org.locationtech.geowave.core.store.query.constraints.SimpleNumericQuery) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 GeotoolsFeatureDataAdapter (org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter)1 SimpleDoubleIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleDoubleIndexStrategy)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Index (org.locationtech.geowave.core.store.api.Index)1 BasicNumericDimensionField (org.locationtech.geowave.core.store.dimension.BasicNumericDimensionField)1 NumericDimensionField (org.locationtech.geowave.core.store.dimension.NumericDimensionField)1 BasicIndexModel (org.locationtech.geowave.core.store.index.BasicIndexModel)1 CustomNameIndex (org.locationtech.geowave.core.store.index.CustomNameIndex)1 SimpleNumericQuery (org.locationtech.geowave.core.store.query.constraints.SimpleNumericQuery)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1