Search in sources :

Example 1 with SimpleIntegerIndexStrategy

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

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

the class GeoWaveAttributeIndexIT method testNumericAttributeIndex.

@Test
public void testNumericAttributeIndex() {
    final DataStore ds = dataStore.createDataStore();
    final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    ds.addType(adapter, spatialIndex);
    Index integerAttributeIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, INTEGER_FIELD));
    ds.addIndex(TYPE_NAME, integerAttributeIndex);
    integerAttributeIndex = ds.getIndex(integerAttributeIndex.getName());
    assertTrue(integerAttributeIndex instanceof AttributeIndex);
    assertEquals(INTEGER_FIELD, ((AttributeIndex) integerAttributeIndex).getAttributeName());
    assertTrue(integerAttributeIndex.getIndexStrategy() instanceof SimpleIntegerIndexStrategy);
    final InternalAdapterStore adapterStore = dataStore.createInternalAdapterStore();
    final AdapterIndexMappingStore mappingStore = dataStore.createAdapterIndexMappingStore();
    // Get the mapping for the attribute index
    final AdapterToIndexMapping mapping = mappingStore.getMapping(adapterStore.getAdapterId(adapter.getTypeName()), integerAttributeIndex.getName());
    assertEquals(1, mapping.getIndexFieldMappers().size());
    final IndexFieldMapper<?, ?> fieldMapper = mapping.getIndexFieldMappers().get(0);
    assertEquals(Integer.class, fieldMapper.adapterFieldType());
    assertEquals(Integer.class, fieldMapper.indexFieldType());
    assertEquals(1, fieldMapper.getAdapterFields().length);
    assertEquals(INTEGER_FIELD, fieldMapper.getAdapterFields()[0]);
    // Ingest data
    ingestData(ds);
    // Query data from attribute index
    try (CloseableIterator<SimpleFeature> iterator = ds.query(QueryBuilder.newBuilder(SimpleFeature.class).indexName(integerAttributeIndex.getName()).build())) {
        assertTrue(iterator.hasNext());
        // Only one quarter of features should be indexed
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    final Filter rangeFilter = NumericFieldValue.of(INTEGER_FIELD).isBetween(1.0, 40.0);
    // Query data from attribute index with a numeric range constraint
    try (CloseableIterator<SimpleFeature> iterator = ds.query(QueryBuilder.newBuilder(SimpleFeature.class).indexName(integerAttributeIndex.getName()).filter(rangeFilter).build())) {
        assertTrue(iterator.hasNext());
        assertEquals(10, Iterators.size(iterator));
    }
}
Also used : InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) CustomIndex(org.locationtech.geowave.core.store.index.CustomIndex) Index(org.locationtech.geowave.core.store.api.Index) AttributeIndex(org.locationtech.geowave.core.store.api.AttributeIndex) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) AttributeIndex(org.locationtech.geowave.core.store.api.AttributeIndex) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) DataStore(org.locationtech.geowave.core.store.api.DataStore) SimpleIntegerIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleIntegerIndexStrategy) Test(org.junit.Test)

Aggregations

SimpleIntegerIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleIntegerIndexStrategy)2 ParameterException (com.beust.jcommander.ParameterException)1 Test (org.junit.Test)1 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)1 NumericIndexStrategy (org.locationtech.geowave.core.index.NumericIndexStrategy)1 SimpleByteIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleByteIndexStrategy)1 SimpleDoubleIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleDoubleIndexStrategy)1 SimpleFloatIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleFloatIndexStrategy)1 SimpleLongIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleLongIndexStrategy)1 SimpleShortIndexStrategy (org.locationtech.geowave.core.index.simple.SimpleShortIndexStrategy)1 AdapterToIndexMapping (org.locationtech.geowave.core.store.AdapterToIndexMapping)1 AdapterIndexMappingStore (org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore)1 InternalAdapterStore (org.locationtech.geowave.core.store.adapter.InternalAdapterStore)1 AttributeIndex (org.locationtech.geowave.core.store.api.AttributeIndex)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 AttributeIndexOptions (org.locationtech.geowave.core.store.index.AttributeIndexOptions)1 CustomIndex (org.locationtech.geowave.core.store.index.CustomIndex)1