use of org.locationtech.geowave.core.store.statistics.StatisticsIngestCallback 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());
}
Aggregations