Search in sources :

Example 1 with SimpleDoubleIndexStrategy

use of org.locationtech.geowave.core.index.simple.SimpleDoubleIndexStrategy in project geowave by locationtech.

the class NumericAttributeIndexProvider method buildIndex.

@Override
public AttributeIndex buildIndex(final String indexName, final DataTypeAdapter<?> adapter, final FieldDescriptor<?> fieldDescriptor) {
    final Class<?> bindingClass = fieldDescriptor.bindingClass();
    final String fieldName = fieldDescriptor.fieldName();
    final NumericIndexStrategy indexStrategy;
    final CommonIndexModel indexModel;
    if (Byte.class.isAssignableFrom(bindingClass)) {
        indexStrategy = new SimpleByteIndexStrategy();
        indexModel = new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>(fieldName, Byte.class) });
    } else if (Short.class.isAssignableFrom(bindingClass)) {
        indexStrategy = new SimpleShortIndexStrategy();
        indexModel = new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>(fieldName, Short.class) });
    } else if (Integer.class.isAssignableFrom(bindingClass)) {
        indexStrategy = new SimpleIntegerIndexStrategy();
        indexModel = new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>(fieldName, Integer.class) });
    } else if (Long.class.isAssignableFrom(bindingClass)) {
        indexStrategy = new SimpleLongIndexStrategy();
        indexModel = new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>(fieldName, Long.class) });
    } else if (Float.class.isAssignableFrom(bindingClass)) {
        indexStrategy = new SimpleFloatIndexStrategy();
        indexModel = new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>(fieldName, Float.class) });
    } else if (Double.class.isAssignableFrom(bindingClass)) {
        indexStrategy = new SimpleDoubleIndexStrategy();
        indexModel = new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>(fieldName, Double.class) });
    } else {
        throw new ParameterException("Unsupported numeric attribute index class: " + bindingClass.getName());
    }
    return new AttributeIndexImpl(indexStrategy, indexModel, indexName, fieldName);
}
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) SimpleLongIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleLongIndexStrategy) SimpleShortIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleShortIndexStrategy) SimpleDoubleIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleDoubleIndexStrategy) SimpleFloatIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleFloatIndexStrategy) ParameterException(com.beust.jcommander.ParameterException) SimpleIntegerIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleIntegerIndexStrategy) SimpleByteIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleByteIndexStrategy) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy)

Example 2 with SimpleDoubleIndexStrategy

use of org.locationtech.geowave.core.index.simple.SimpleDoubleIndexStrategy 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

SimpleDoubleIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleDoubleIndexStrategy)2 BasicNumericDimensionField (org.locationtech.geowave.core.store.dimension.BasicNumericDimensionField)2 NumericDimensionField (org.locationtech.geowave.core.store.dimension.NumericDimensionField)2 ParameterException (com.beust.jcommander.ParameterException)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 GeotoolsFeatureDataAdapter (org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter)1 NumericIndexStrategy (org.locationtech.geowave.core.index.NumericIndexStrategy)1 SimpleByteIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleByteIndexStrategy)1 SimpleFloatIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleFloatIndexStrategy)1 SimpleIntegerIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleIntegerIndexStrategy)1 SimpleLongIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleLongIndexStrategy)1 SimpleShortIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleShortIndexStrategy)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Index (org.locationtech.geowave.core.store.api.Index)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