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);
}
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));
}
}
Aggregations