Search in sources :

Example 1 with StatisticId

use of org.locationtech.geowave.core.store.statistics.StatisticId in project geowave by locationtech.

the class AbstractGeoWaveBasicVectorIT method testStats.

@SuppressWarnings("unchecked")
protected void testStats(final URL[] inputFiles, final boolean multithreaded, final CoordinateReferenceSystem crs, final Index... indices) {
    // In the multithreaded case, only test min/max and count. Stats will be
    // ingested/ in a different order and will not match.
    final LocalFileIngestPlugin<SimpleFeature> localFileIngest = new GeoToolsVectorDataStoreIngestPlugin(Filter.INCLUDE);
    final Map<String, StatisticsCache> statsCache = new HashMap<>();
    final String[] indexNames = Arrays.stream(indices).map(i -> i.getName()).toArray(i -> new String[i]);
    for (final URL inputFile : inputFiles) {
        LOGGER.warn("Calculating stats from file '" + inputFile.getPath() + "' - this may take several minutes...");
        try (final CloseableIterator<GeoWaveData<SimpleFeature>> dataIterator = localFileIngest.toGeoWaveData(inputFile, indexNames)) {
            final TransientAdapterStore adapterCache = new MemoryAdapterStore(localFileIngest.getDataAdapters());
            while (dataIterator.hasNext()) {
                final GeoWaveData<SimpleFeature> data = dataIterator.next();
                final DataTypeAdapter<SimpleFeature> adapter = data.getAdapter(adapterCache);
                // it should be a statistical data adapter
                if (adapter instanceof DefaultStatisticsProvider) {
                    StatisticsCache cachedValues = statsCache.get(adapter.getTypeName());
                    if (cachedValues == null) {
                        cachedValues = new StatisticsCache(adapter, crs);
                        statsCache.put(adapter.getTypeName(), cachedValues);
                    }
                    cachedValues.entryIngested(data.getValue());
                }
            }
        }
    }
    final DataStatisticsStore statsStore = getDataStorePluginOptions().createDataStatisticsStore();
    final PersistentAdapterStore adapterStore = getDataStorePluginOptions().createAdapterStore();
    final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
    for (final InternalDataAdapter<?> internalDataAdapter : adapters) {
        final FeatureDataAdapter adapter = (FeatureDataAdapter) internalDataAdapter.getAdapter();
        final StatisticsCache cachedValue = statsCache.get(adapter.getTypeName());
        Assert.assertNotNull(cachedValue);
        final Set<Entry<Statistic<?>, Map<ByteArray, StatisticValue<?>>>> expectedStats = cachedValue.statsCache.entrySet();
        int statsCount = 0;
        try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIterator = statsStore.getDataTypeStatistics(adapter, null, null)) {
            while (statsIterator.hasNext()) {
                statsIterator.next();
                statsCount++;
            }
        }
        try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIterator = statsStore.getFieldStatistics(adapter, null, null, null)) {
            while (statsIterator.hasNext()) {
                statsIterator.next();
                statsCount++;
            }
        }
        Assert.assertEquals("The number of stats for data adapter '" + adapter.getTypeName() + "' do not match count expected", expectedStats.size(), statsCount);
        for (final Entry<Statistic<?>, Map<ByteArray, StatisticValue<?>>> expectedStat : expectedStats) {
            for (final Entry<ByteArray, StatisticValue<?>> expectedValues : expectedStat.getValue().entrySet()) {
                StatisticValue<Object> actual;
                if (expectedValues.getKey().equals(StatisticValue.NO_BIN)) {
                    actual = statsStore.getStatisticValue((Statistic<StatisticValue<Object>>) expectedStat.getKey());
                } else {
                    actual = statsStore.getStatisticValue((Statistic<StatisticValue<Object>>) expectedStat.getKey(), expectedValues.getKey());
                }
                assertEquals(expectedValues.getValue().getValue(), actual.getValue());
            }
        }
        // finally check the one stat that is more manually calculated -
        // the bounding box
        StatisticQuery<BoundingBoxValue, Envelope> query = StatisticQueryBuilder.newBuilder(BoundingBoxStatistic.STATS_TYPE).fieldName(adapter.getFeatureType().getGeometryDescriptor().getLocalName()).typeName(adapter.getTypeName()).build();
        BoundingBoxValue bboxStat = getDataStorePluginOptions().createDataStore().aggregateStatistics(query);
        validateBBox(bboxStat.getValue(), cachedValue);
        // now make sure it works without giving field name because there is only one geometry field
        // anyways
        query = StatisticQueryBuilder.newBuilder(BoundingBoxStatistic.STATS_TYPE).typeName(adapter.getTypeName()).build();
        bboxStat = getDataStorePluginOptions().createDataStore().aggregateStatistics(query);
        validateBBox(bboxStat.getValue(), cachedValue);
        final StatisticId<BoundingBoxValue> bboxStatId = FieldStatistic.generateStatisticId(adapter.getTypeName(), BoundingBoxStatistic.STATS_TYPE, adapter.getFeatureType().getGeometryDescriptor().getLocalName(), Statistic.INTERNAL_TAG);
        Assert.assertTrue("Unable to remove individual stat", statsStore.removeStatistic(statsStore.getStatisticById(bboxStatId)));
        Assert.assertNull("Individual stat was not successfully removed", statsStore.getStatisticById(bboxStatId));
    }
}
Also used : FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) Arrays(java.util.Arrays) GeoWaveData(org.locationtech.geowave.core.store.ingest.GeoWaveData) URL(java.net.URL) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CommonIndexAggregation(org.locationtech.geowave.core.store.query.aggregate.CommonIndexAggregation) LoggerFactory(org.slf4j.LoggerFactory) Aggregation(org.locationtech.geowave.core.store.api.Aggregation) MathUtils(org.apache.commons.math.util.MathUtils) TestUtils(org.locationtech.geowave.test.TestUtils) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) ByteBuffer(java.nio.ByteBuffer) TimeDescriptors(org.locationtech.geowave.core.geotime.util.TimeDescriptors) TransientAdapterStore(org.locationtech.geowave.core.store.adapter.TransientAdapterStore) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) Pair(org.apache.commons.lang3.tuple.Pair) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Map(java.util.Map) Statistic(org.locationtech.geowave.core.store.api.Statistic) Maps(jersey.repackaged.com.google.common.collect.Maps) Persistable(org.locationtech.geowave.core.index.persist.Persistable) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) StatisticQuery(org.locationtech.geowave.core.store.api.StatisticQuery) Set(java.util.Set) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) DimensionalityType(org.locationtech.geowave.test.TestUtils.DimensionalityType) ExpectedResults(org.locationtech.geowave.test.TestUtils.ExpectedResults) ConfigOptions(org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions) List(java.util.List) VectorLocalExportOptions(org.locationtech.geowave.adapter.vector.export.VectorLocalExportOptions) Entry(java.util.Map.Entry) DataIdQuery(org.locationtech.geowave.core.store.query.constraints.DataIdQuery) Geometry(org.locationtech.jts.geom.Geometry) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ByteArray(org.locationtech.geowave.core.index.ByteArray) AggregationQuery(org.locationtech.geowave.core.store.api.AggregationQuery) BeforeClass(org.junit.BeforeClass) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) AggregationQueryBuilder(org.locationtech.geowave.core.store.api.AggregationQueryBuilder) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommonIndexedPersistenceEncoding(org.locationtech.geowave.core.store.data.CommonIndexedPersistenceEncoding) HashSet(java.util.HashSet) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) LocalFileIngestPlugin(org.locationtech.geowave.core.store.ingest.LocalFileIngestPlugin) Calendar(java.util.Calendar) Lists(com.google.common.collect.Lists) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) StatisticQueryBuilder(org.locationtech.geowave.core.store.api.StatisticQueryBuilder) QueryBuilder(org.locationtech.geowave.core.store.api.QueryBuilder) Index(org.locationtech.geowave.core.store.api.Index) StatisticsIngestCallback(org.locationtech.geowave.core.store.statistics.StatisticsIngestCallback) BoundingBoxStatistic(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) Logger(org.slf4j.Logger) DataStore(org.locationtech.geowave.core.store.api.DataStore) OptimalCQLQuery(org.locationtech.geowave.core.geotime.store.query.OptimalCQLQuery) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) IngestCallback(org.locationtech.geowave.core.store.callback.IngestCallback) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) VectorLocalExportCommand(org.locationtech.geowave.adapter.vector.export.VectorLocalExportCommand) File(java.io.File) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) InternalGeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.InternalGeotoolsFeatureDataAdapter) MemoryAdapterStore(org.locationtech.geowave.core.store.memory.MemoryAdapterStore) Filter(org.opengis.filter.Filter) ZipUtils(org.locationtech.geowave.adapter.raster.util.ZipUtils) Assert(org.junit.Assert) GeoToolsVectorDataStoreIngestPlugin(org.locationtech.geowave.format.geotools.vector.GeoToolsVectorDataStoreIngestPlugin) Envelope(org.locationtech.jts.geom.Envelope) Assert.assertEquals(org.junit.Assert.assertEquals) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) HashMap(java.util.HashMap) GeoToolsVectorDataStoreIngestPlugin(org.locationtech.geowave.format.geotools.vector.GeoToolsVectorDataStoreIngestPlugin) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) Envelope(org.locationtech.jts.geom.Envelope) URL(java.net.URL) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) Entry(java.util.Map.Entry) Statistic(org.locationtech.geowave.core.store.api.Statistic) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) BoundingBoxStatistic(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) ByteArray(org.locationtech.geowave.core.index.ByteArray) TransientAdapterStore(org.locationtech.geowave.core.store.adapter.TransientAdapterStore) MemoryAdapterStore(org.locationtech.geowave.core.store.memory.MemoryAdapterStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) GeoWaveData(org.locationtech.geowave.core.store.ingest.GeoWaveData) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) InternalGeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.InternalGeotoolsFeatureDataAdapter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with StatisticId

use of org.locationtech.geowave.core.store.statistics.StatisticId in project geowave by locationtech.

the class OptimalExpressionQuery method determineBestIndices.

@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Pair<Index, List<InternalDataAdapter<?>>>> determineBestIndices(final BaseQueryOptions baseOptions, final InternalDataAdapter<?>[] adapters, final AdapterIndexMappingStore adapterIndexMappingStore, final IndexStore indexStore, final DataStatisticsStore statisticsStore) {
    final Map<Index, List<InternalDataAdapter<?>>> bestIndices = Maps.newHashMap();
    final Set<String> referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    for (final InternalDataAdapter<?> adapter : adapters) {
        if (!adapterMatchesFilter(adapter, referencedFields)) {
            continue;
        }
        final AdapterToIndexMapping[] adapterIndices = adapterIndexMappingStore.getIndicesForAdapter(adapter.getAdapterId());
        final Map<Index, FilterConstraints<?>> indexConstraints = Maps.newHashMap();
        Index bestIndex = null;
        for (final AdapterToIndexMapping mapping : adapterIndices) {
            if ((baseOptions.getIndexName() != null) && !baseOptions.getIndexName().equals(mapping.getIndexName())) {
                continue;
            }
            final Index index = mapping.getIndex(indexStore);
            if (indexFilter != null && !indexFilter.test(index)) {
                continue;
            }
            if ((bestIndex == null) || ((bestIndex instanceof AttributeIndex) && !(index instanceof AttributeIndex))) {
                bestIndex = index;
            }
            final Set<String> indexedFields = Sets.newHashSet();
            final Class<? extends Comparable> filterClass;
            if ((index instanceof CustomIndex) && (((CustomIndex<?, ?>) index).getCustomIndexStrategy() instanceof TextIndexStrategy)) {
                final TextIndexStrategy<?> indexStrategy = (TextIndexStrategy<?>) ((CustomIndex<?, ?>) index).getCustomIndexStrategy();
                if (!(indexStrategy.getEntryConverter() instanceof AdapterFieldTextIndexEntryConverter)) {
                    continue;
                }
                indexedFields.add(((AdapterFieldTextIndexEntryConverter<?>) indexStrategy.getEntryConverter()).getFieldName());
                filterClass = String.class;
            } else {
                for (final IndexFieldMapper<?, ?> mapper : mapping.getIndexFieldMappers()) {
                    for (final String adapterField : mapper.getAdapterFields()) {
                        indexedFields.add(adapterField);
                    }
                }
                // Remove any fields that are part of the common index model, but not used in the index
                // strategy. They shouldn't be considered when trying to find a best match. In the future
                // it may be useful to consider an index that has extra common index dimensions that
                // contain filtered fields over one that only matches indexed dimensions. For example, if
                // I have a spatial index, and a spatial index that stores time, it should pick the one
                // that stores time if I supply a temporal constraint, even though it isn't part of the
                // index strategy.
                final int modelDimensions = index.getIndexModel().getDimensions().length;
                final int strategyDimensions = index.getIndexStrategy().getOrderedDimensionDefinitions().length;
                for (int i = modelDimensions - 1; i >= strategyDimensions; i--) {
                    final IndexFieldMapper<?, ?> mapper = mapping.getMapperForIndexField(index.getIndexModel().getDimensions()[i].getFieldName());
                    for (final String adapterField : mapper.getAdapterFields()) {
                        indexedFields.remove(adapterField);
                    }
                }
                filterClass = Double.class;
            }
            if (referencedFields.containsAll(indexedFields)) {
                final FilterConstraints<?> constraints = filter.getConstraints(filterClass, statisticsStore, adapter, mapping, index, indexedFields);
                if (constraints.constrainsAllFields(indexedFields)) {
                    indexConstraints.put(index, constraints);
                }
            }
        }
        if (indexConstraints.size() == 1) {
            final Entry<Index, FilterConstraints<?>> bestEntry = indexConstraints.entrySet().iterator().next();
            bestIndex = bestEntry.getKey();
            constraintCache.put(adapter.getTypeName(), bestEntry.getValue());
        } else if (indexConstraints.size() > 1) {
            // determine which constraint is the best
            double bestCardinality = Double.MAX_VALUE;
            Index bestConstrainedIndex = null;
            for (final Entry<Index, FilterConstraints<?>> entry : indexConstraints.entrySet()) {
                final QueryRanges ranges = entry.getValue().getQueryRanges(baseOptions, statisticsStore);
                if (ranges.isEmpty()) {
                    continue;
                }
                // TODO: A future optimization would be to add a default numeric histogram for any numeric
                // index dimensions and just use the index data ranges to determine cardinality rather
                // than decomposing query ranges.
                final StatisticId<RowRangeHistogramValue> statisticId = IndexStatistic.generateStatisticId(entry.getKey().getName(), RowRangeHistogramStatistic.STATS_TYPE, Statistic.INTERNAL_TAG);
                final RowRangeHistogramStatistic histogram = (RowRangeHistogramStatistic) statisticsStore.getStatisticById(statisticId);
                final double cardinality = DataStoreUtils.cardinality(statisticsStore, histogram, adapter, bestConstrainedIndex, ranges);
                if ((bestConstrainedIndex == null) || (cardinality < bestCardinality)) {
                    bestConstrainedIndex = entry.getKey();
                    bestCardinality = cardinality;
                }
            }
            if (bestConstrainedIndex != null) {
                bestIndex = bestConstrainedIndex;
                constraintCache.put(adapter.getTypeName(), indexConstraints.get(bestIndex));
            }
        }
        if (bestIndex == null) {
            continue;
        }
        if (!bestIndices.containsKey(bestIndex)) {
            bestIndices.put(bestIndex, Lists.newArrayList());
        }
        bestIndices.get(bestIndex).add(adapter);
    }
    return bestIndices.entrySet().stream().map(e -> Pair.of(e.getKey(), e.getValue())).collect(Collectors.toList());
}
Also used : RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) IndexFilter(org.locationtech.geowave.core.store.index.IndexFilter) PersistenceUtils(org.locationtech.geowave.core.index.persist.PersistenceUtils) IndexFieldMapper(org.locationtech.geowave.core.store.api.IndexFieldMapper) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) LoggerFactory(org.slf4j.LoggerFactory) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) ByteBuffer(java.nio.ByteBuffer) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) CustomIndex(org.locationtech.geowave.core.store.index.CustomIndex) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) Sets(com.beust.jcommander.internal.Sets) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) Statistic(org.locationtech.geowave.core.store.api.Statistic) TextIndexStrategy(org.locationtech.geowave.core.index.text.TextIndexStrategy) VarintUtils(org.locationtech.geowave.core.index.VarintUtils) Index(org.locationtech.geowave.core.store.api.Index) DataStoreUtils(org.locationtech.geowave.core.store.util.DataStoreUtils) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) BaseQueryOptions(org.locationtech.geowave.core.store.base.BaseQueryOptions) Logger(org.slf4j.Logger) AdapterFieldTextIndexEntryConverter(org.locationtech.geowave.core.store.index.TextAttributeIndexProvider.AdapterFieldTextIndexEntryConverter) Set(java.util.Set) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) AttributeIndex(org.locationtech.geowave.core.store.api.AttributeIndex) List(java.util.List) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) FilterConstraints(org.locationtech.geowave.core.store.query.filter.expression.FilterConstraints) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Entry(java.util.Map.Entry) ExplicitTextSearch(org.locationtech.geowave.core.index.text.ExplicitTextSearch) RowRangeHistogramValue(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) 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) Entry(java.util.Map.Entry) AttributeIndex(org.locationtech.geowave.core.store.api.AttributeIndex) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) List(java.util.List) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) AdapterFieldTextIndexEntryConverter(org.locationtech.geowave.core.store.index.TextAttributeIndexProvider.AdapterFieldTextIndexEntryConverter) FilterConstraints(org.locationtech.geowave.core.store.query.filter.expression.FilterConstraints) TextIndexStrategy(org.locationtech.geowave.core.index.text.TextIndexStrategy) CustomIndex(org.locationtech.geowave.core.store.index.CustomIndex)

Example 3 with StatisticId

use of org.locationtech.geowave.core.store.statistics.StatisticId in project geowave by locationtech.

the class ChooseBestMatchIndexQueryStrategyTest method testChooseSpatialTemporalWithStats.

@Test
public void testChooseSpatialTemporalWithStats() {
    final Index temporalindex = new SpatialTemporalIndexBuilder().createIndex();
    final Index spatialIndex = new SpatialIndexBuilder().createIndex();
    final RowRangeHistogramStatistic rangeTempStats = new RowRangeHistogramStatistic(temporalindex.getName());
    rangeTempStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeTempStats.setInternal();
    final RowRangeHistogramStatistic rangeStats = new RowRangeHistogramStatistic(spatialIndex.getName());
    rangeStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeStats.setInternal();
    final Map<StatisticId<?>, Map<ByteArray, StatisticValue<?>>> statsMap = new HashMap<>();
    final ChooseBestMatchIndexQueryStrategy strategy = new ChooseBestMatchIndexQueryStrategy();
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(LatitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
    cs1.addConstraint(LongitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.4, 0.7), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(TimeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.1, 0.2), true));
    final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a)).merge(Collections.singletonList(cs1));
    final BasicQueryByClass query = new BasicQueryByClass(constraints);
    final NumericIndexStrategy temporalIndexStrategy = new SpatialTemporalIndexBuilder().createIndex().getIndexStrategy();
    final Random r = new Random(SEED);
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = temporalIndexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeTempStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeTempStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeTempStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Index index = new SpatialIndexBuilder().createIndex();
    final NumericIndexStrategy indexStrategy = index.getIndexStrategy();
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = indexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Iterator<Index> it = getIndices(new TestDataStatisticsStore(Lists.newArrayList(rangeStats, rangeTempStats), statsMap), query, strategy);
    assertTrue(it.hasNext());
    assertEquals(temporalindex.getName(), it.next().getName());
    assertFalse(it.hasNext());
}
Also used : SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) HashMap(java.util.HashMap) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) NullIndex(org.locationtech.geowave.core.store.index.NullIndex) Index(org.locationtech.geowave.core.store.api.Index) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) Random(java.util.Random) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) ByteArray(org.locationtech.geowave.core.index.ByteArray) StatisticsIngestCallback(org.locationtech.geowave.core.store.statistics.StatisticsIngestCallback) ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) RowRangeHistogramValue(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) CompositeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy) GeoWaveKeyImpl(org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) PartitionBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.PartitionBinningStrategy) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue) Map(java.util.Map) HashMap(java.util.HashMap) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) Test(org.junit.Test)

Aggregations

Map (java.util.Map)3 Index (org.locationtech.geowave.core.store.api.Index)3 StatisticId (org.locationtech.geowave.core.store.statistics.StatisticId)3 Lists (com.google.common.collect.Lists)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Pair (org.apache.commons.lang3.tuple.Pair)2 InternalDataAdapter (org.locationtech.geowave.core.store.adapter.InternalDataAdapter)2 DataTypeAdapter (org.locationtech.geowave.core.store.api.DataTypeAdapter)2 Statistic (org.locationtech.geowave.core.store.api.Statistic)2 DataStatisticsStore (org.locationtech.geowave.core.store.statistics.DataStatisticsStore)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Sets (com.beust.jcommander.internal.Sets)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 IOException (java.io.IOException)1