use of org.locationtech.geowave.core.store.index.IndexImpl in project geowave by locationtech.
the class AggregationIterator method aggregateRow.
protected void aggregateRow(final Text currentRow, final CommonIndexModel model, final CommonIndexedPersistenceEncoding persistenceEncoding) {
if (adapter == null) {
aggregationFunction.aggregate(null, persistenceEncoding);
endRowOfAggregation = currentRow;
} else if (((Short) (persistenceEncoding.getInternalAdapterId())).equals((adapter.getAdapterId()))) {
final PersistentDataset<Object> adapterExtendedValues = new MultiFieldPersistentDataset<>();
if (persistenceEncoding instanceof AbstractAdapterPersistenceEncoding) {
((AbstractAdapterPersistenceEncoding) persistenceEncoding).convertUnknownValues(adapter, model);
final PersistentDataset<Object> existingExtValues = ((AbstractAdapterPersistenceEncoding) persistenceEncoding).getAdapterExtendedData();
if (existingExtValues != null) {
adapterExtendedValues.addValues(existingExtValues.getValues());
}
}
final IndexedAdapterPersistenceEncoding encoding = new IndexedAdapterPersistenceEncoding(persistenceEncoding.getInternalAdapterId(), persistenceEncoding.getDataId(), persistenceEncoding.getInsertionPartitionKey(), persistenceEncoding.getInsertionSortKey(), persistenceEncoding.getDuplicateCount(), persistenceEncoding.getCommonData(), new MultiFieldPersistentDataset<byte[]>(), adapterExtendedValues);
// the data adapter can't use the numeric index strategy and only
// the common index model to decode which is the case for feature
// data, we pass along a null strategy to eliminate the necessity to
// send a serialization of the strategy in the options of this
// iterator
final Object row = adapter.decode(encoding, indexMapping, new IndexImpl(null, model));
if (row != null) {
// for now ignore field info
aggregationFunction.aggregate(adapter, row);
endRowOfAggregation = currentRow;
}
}
}
use of org.locationtech.geowave.core.store.index.IndexImpl in project geowave by locationtech.
the class AbstractPartitioner method initIndex.
protected void initIndex(final CommonIndexModel indexModel, final double[] distancePerDimensionForIndex) {
// truncating to lower precision
final NumericDimensionField<?>[] dimensions = indexModel.getDimensions();
int totalRequestedPrecision = 0;
final int[] dimensionPrecision = new int[indexModel.getDimensions().length];
for (int i = 0; i < dimensionPrecision.length; i++) {
// total
final double distance = distancePerDimensionForIndex[i] * 2.0;
// width...(radius)
// adjust by precision factory (0 to 1.0)
dimensionPrecision[i] = (int) (precisionFactor * Math.abs((int) (Math.log(dimensions[i].getRange() / distance) / Math.log(2))));
totalRequestedPrecision += dimensionPrecision[i];
}
if (totalRequestedPrecision > 63) {
final double rescale = 63.0 / totalRequestedPrecision;
for (int i = 0; i < dimensionPrecision.length; i++) {
dimensionPrecision[i] = (int) (rescale * dimensionPrecision[i]);
}
}
final TieredSFCIndexStrategy indexStrategy = TieredSFCIndexFactory.createSingleTierStrategy(indexModel.getDimensions(), dimensionPrecision, SFCType.HILBERT);
// Not relevant since this is a single tier strategy.
// For now, just setting to a non-zero reasonable value
indexStrategy.setMaxEstimatedDuplicateIdsPerDimension(2);
index = new IndexImpl(indexStrategy, indexModel);
}
use of org.locationtech.geowave.core.store.index.IndexImpl in project geowave by locationtech.
the class PersistenceEncodingTest method testLineWithPrecisionOnTheTileEdge.
@Test
public void testLineWithPrecisionOnTheTileEdge() {
final NumericIndexStrategy strategy = TieredSFCIndexFactory.createSingleTierStrategy(SPATIAL_TEMPORAL_DIMENSIONS, new int[] { 14, 14, 14 }, SFCType.HILBERT);
final Index index = new IndexImpl(strategy, model);
final GeoObjDataAdapter adapter = new GeoObjDataAdapter(false);
final AdapterToIndexMapping indexMapping = BaseDataStoreUtils.mapAdapterToIndex(adapter.asInternalAdapter((short) -1), index);
final GeoObj entry = new GeoObj(factory.createLineString(new Coordinate[] { // notice
new Coordinate(-99.22, 33.75000000000001), // 33.75
new Coordinate(-99.15, 33.75000000000001) // notice that this gets tiled as 33.75
}), new Date(352771200000l), new Date(352771200000l), "g1");
final List<byte[]> ids = adapter.asInternalAdapter((short) -1).encode(entry, indexMapping, index).getInsertionIds(index).getCompositeInsertionIds();
assertEquals(4, ids.size());
}
use of org.locationtech.geowave.core.store.index.IndexImpl in project geowave by locationtech.
the class MemoryDataStoreTest method testMultipleIndices.
@Test
public void testMultipleIndices() throws IOException {
final Index index1 = new IndexImpl(new MockComponents.MockIndexStrategy(), new MockComponents.TestIndexModel("tm1"));
final Index index2 = new IndexImpl(new MockComponents.MockIndexStrategy(), new MockComponents.TestIndexModel("tm2"));
final String namespace = "test2_" + getClass().getName();
final StoreFactoryFamilySpi storeFamily = new MemoryStoreFactoryFamily();
final MemoryRequiredOptions opts = new MemoryRequiredOptions();
opts.setGeoWaveNamespace(namespace);
final DataStore dataStore = storeFamily.getDataStoreFactory().createStore(opts);
final DataStatisticsStore statsStore = storeFamily.getDataStatisticsStoreFactory().createStore(opts);
final DataTypeAdapter<Integer> adapter = new MockComponents.MockAbstractDataAdapter();
final VisibilityHandler visHandler = new GlobalVisibilityHandler("aaa&bbb");
final List<Statistic<?>> statistics = Lists.newArrayList();
statistics.add(new NumericRangeStatistic(adapter.getTypeName(), MockAbstractDataAdapter.INTEGER));
dataStore.addType(adapter, statistics, index1, index2);
try (final Writer<Integer> indexWriter = dataStore.createWriter(adapter.getTypeName())) {
indexWriter.write(new Integer(25), visHandler);
indexWriter.flush();
indexWriter.write(new Integer(35), visHandler);
indexWriter.flush();
}
// authorization check
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index2.getName()).addAuthorization("aaa").constraints(new TestQuery(23, 26)).build())) {
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index1.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 26)).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(25), itemIt.next());
assertFalse(itemIt.hasNext());
}
// pick an index
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 36)).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(25), itemIt.next());
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIt = statsStore.getAllStatistics(null)) {
try (CloseableIterator<? extends StatisticValue<?>> statisticValues = statsStore.getStatisticValues(statsIt, null, "aaa", "bbb")) {
assertTrue(checkStats(statisticValues, 2, new NumericRange(25, 35)));
}
}
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIt = statsStore.getAllStatistics(null)) {
try (CloseableIterator<? extends StatisticValue<?>> statisticValues = statsStore.getStatisticValues(statsIt, null)) {
assertTrue(checkStats(statisticValues, 0, null));
}
}
dataStore.delete(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 26)).build());
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index1.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 36)).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index2.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 36)).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index1.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 26)).build())) {
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index2.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 26)).build())) {
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index1.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new DataIdQuery(adapter.getDataId(new Integer(35)))).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index2.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new DataIdQuery(adapter.getDataId(new Integer(35)))).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
}
}
use of org.locationtech.geowave.core.store.index.IndexImpl in project geowave by locationtech.
the class MemoryDataStoreTest method test.
@Test
public void test() throws IOException {
final Index index = new IndexImpl(new MockComponents.MockIndexStrategy(), new MockComponents.TestIndexModel());
final String namespace = "test_" + getClass().getName();
final StoreFactoryFamilySpi storeFamily = new MemoryStoreFactoryFamily();
final MemoryRequiredOptions reqOptions = new MemoryRequiredOptions();
reqOptions.setGeoWaveNamespace(namespace);
final DataStore dataStore = storeFamily.getDataStoreFactory().createStore(reqOptions);
final DataStatisticsStore statsStore = storeFamily.getDataStatisticsStoreFactory().createStore(reqOptions);
final DataTypeAdapter<Integer> adapter = new MockComponents.MockAbstractDataAdapter();
final VisibilityHandler visHandler = new GlobalVisibilityHandler("aaa&bbb");
final List<Statistic<?>> statistics = Lists.newArrayList();
statistics.add(new CountStatistic(adapter.getTypeName()));
statistics.add(new NumericRangeStatistic(adapter.getTypeName(), MockAbstractDataAdapter.INTEGER));
dataStore.addType(adapter, statistics, index);
try (final Writer<Integer> indexWriter = dataStore.createWriter(adapter.getTypeName())) {
indexWriter.write(new Integer(25), visHandler);
indexWriter.flush();
indexWriter.write(new Integer(35), visHandler);
indexWriter.flush();
}
// authorization check
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).addAuthorization("aaa").constraints(new TestQuery(23, 26)).build())) {
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 26)).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(25), itemIt.next());
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 36)).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(25), itemIt.next());
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIt = statsStore.getAllStatistics(null)) {
try (CloseableIterator<? extends StatisticValue<?>> statisticValues = statsStore.getStatisticValues(statsIt, null, "aaa", "bbb")) {
assertTrue(checkStats(statisticValues, 2, new NumericRange(25, 35)));
}
}
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIt = statsStore.getAllStatistics(null)) {
try (CloseableIterator<? extends StatisticValue<?>> statisticValues = statsStore.getStatisticValues(statsIt, null)) {
assertTrue(checkStats(statisticValues, 0, null));
}
}
dataStore.delete(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 26)).build());
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 36)).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new TestQuery(23, 26)).build())) {
assertFalse(itemIt.hasNext());
}
try (CloseableIterator<?> itemIt = dataStore.query(QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).addAuthorization("aaa").addAuthorization("bbb").constraints(new DataIdQuery(adapter.getDataId(new Integer(35)))).build())) {
assertTrue(itemIt.hasNext());
assertEquals(new Integer(35), itemIt.next());
}
}
Aggregations