Search in sources :

Example 1 with IndexImpl

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;
        }
    }
}
Also used : AbstractAdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AbstractAdapterPersistenceEncoding) MultiFieldPersistentDataset(org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl) IndexedAdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding) PersistentDataset(org.locationtech.geowave.core.store.data.PersistentDataset) MultiFieldPersistentDataset(org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset)

Example 2 with IndexImpl

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);
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) TieredSFCIndexStrategy(org.locationtech.geowave.core.index.sfc.tiered.TieredSFCIndexStrategy) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl)

Example 3 with IndexImpl

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());
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index) Date(java.util.Date) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) Test(org.junit.Test)

Example 4 with IndexImpl

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());
    }
}
Also used : NumericRangeStatistic(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic) Index(org.locationtech.geowave.core.store.api.Index) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) MockAbstractDataAdapter(org.locationtech.geowave.core.store.adapter.MockComponents.MockAbstractDataAdapter) Statistic(org.locationtech.geowave.core.store.api.Statistic) CountStatistic(org.locationtech.geowave.core.store.statistics.adapter.CountStatistic) NumericRangeStatistic(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic) MockComponents(org.locationtech.geowave.core.store.adapter.MockComponents) DataStore(org.locationtech.geowave.core.store.api.DataStore) GlobalVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler) DataIdQuery(org.locationtech.geowave.core.store.query.constraints.DataIdQuery) StoreFactoryFamilySpi(org.locationtech.geowave.core.store.StoreFactoryFamilySpi) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl) GlobalVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) Test(org.junit.Test)

Example 5 with IndexImpl

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());
    }
}
Also used : NumericRangeStatistic(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic) Index(org.locationtech.geowave.core.store.api.Index) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) MockAbstractDataAdapter(org.locationtech.geowave.core.store.adapter.MockComponents.MockAbstractDataAdapter) Statistic(org.locationtech.geowave.core.store.api.Statistic) CountStatistic(org.locationtech.geowave.core.store.statistics.adapter.CountStatistic) NumericRangeStatistic(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic) MockComponents(org.locationtech.geowave.core.store.adapter.MockComponents) DataStore(org.locationtech.geowave.core.store.api.DataStore) GlobalVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler) DataIdQuery(org.locationtech.geowave.core.store.query.constraints.DataIdQuery) CountStatistic(org.locationtech.geowave.core.store.statistics.adapter.CountStatistic) StoreFactoryFamilySpi(org.locationtech.geowave.core.store.StoreFactoryFamilySpi) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl) GlobalVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) Test(org.junit.Test)

Aggregations

IndexImpl (org.locationtech.geowave.core.store.index.IndexImpl)9 Test (org.junit.Test)6 Index (org.locationtech.geowave.core.store.api.Index)5 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)3 MultiFieldPersistentDataset (org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset)3 NumericDimensionField (org.locationtech.geowave.core.store.dimension.NumericDimensionField)3 ArrayList (java.util.ArrayList)2 BasicNumericDataset (org.locationtech.geowave.core.index.numeric.BasicNumericDataset)2 NumericData (org.locationtech.geowave.core.index.numeric.NumericData)2 NumericRange (org.locationtech.geowave.core.index.numeric.NumericRange)2 StoreFactoryFamilySpi (org.locationtech.geowave.core.store.StoreFactoryFamilySpi)2 AbstractAdapterPersistenceEncoding (org.locationtech.geowave.core.store.adapter.AbstractAdapterPersistenceEncoding)2 IndexedAdapterPersistenceEncoding (org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding)2 MockComponents (org.locationtech.geowave.core.store.adapter.MockComponents)2 MockAbstractDataAdapter (org.locationtech.geowave.core.store.adapter.MockComponents.MockAbstractDataAdapter)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 Statistic (org.locationtech.geowave.core.store.api.Statistic)2 VisibilityHandler (org.locationtech.geowave.core.store.api.VisibilityHandler)2 GlobalVisibilityHandler (org.locationtech.geowave.core.store.data.visibility.GlobalVisibilityHandler)2 BasicIndexModel (org.locationtech.geowave.core.store.index.BasicIndexModel)2