use of org.locationtech.geowave.core.store.statistics.field.BloomFilterStatistic in project geowave by locationtech.
the class GeoWaveStatisticsIT method testAddStatistic.
@Test
public void testAddStatistic() {
final DataStore ds = dataStore.createDataStore();
final NumericRangeStatistic longitudeRange = new NumericRangeStatistic(SimpleIngest.FEATURE_NAME, "Longitude");
final NumericRangeStatistic latitudeRange = new NumericRangeStatistic(SimpleIngest.FEATURE_NAME, "Latitude");
final TimeRangeStatistic timeRange = new TimeRangeStatistic(SimpleIngest.FEATURE_NAME, "TimeStamp");
final NumericStatsStatistic latitudeStats = new NumericStatsStatistic(SimpleIngest.FEATURE_NAME, "Latitude");
final BloomFilterStatistic latitudeBloomFilter = new BloomFilterStatistic(SimpleIngest.FEATURE_NAME, "Latitude");
final NumericHistogramStatistic latitudeHistogram = new NumericHistogramStatistic(SimpleIngest.FEATURE_NAME, "Latitude");
ds.addStatistic(longitudeRange, timeRange, latitudeStats, latitudeBloomFilter, latitudeHistogram);
ds.addEmptyStatistic(latitudeRange);
try (CloseableIterator<NumericRangeValue> iterator = ds.queryStatistics(StatisticQueryBuilder.newBuilder(NumericRangeStatistic.STATS_TYPE).typeName(SimpleIngest.FEATURE_NAME).fieldName("Longitude").build())) {
assertTrue(iterator.hasNext());
final NumericRangeValue value = iterator.next();
assertEquals(-165.0, value.getMin(), 0.1);
assertEquals(180.0, value.getMax(), 0.1);
assertFalse(iterator.hasNext());
}
try (CloseableIterator<NumericRangeValue> iterator = ds.queryStatistics(StatisticQueryBuilder.newBuilder(NumericRangeStatistic.STATS_TYPE).typeName(SimpleIngest.FEATURE_NAME).fieldName("Latitude").build())) {
// We only calculated stats for Longitude
assertTrue(iterator.hasNext());
assertFalse(iterator.next().isSet());
assertFalse(iterator.hasNext());
}
final Interval interval = ds.getStatisticValue(timeRange);
try (CloseableIterator<SimpleFeature> it = ds.query(VectorQueryBuilder.newBuilder().build())) {
long min = Long.MAX_VALUE, max = Long.MIN_VALUE;
while (it.hasNext()) {
final long time = ((Date) it.next().getAttribute("TimeStamp")).getTime();
min = Math.min(min, time);
max = Math.max(max, time);
}
assertEquals(min, interval.getStart().toEpochMilli());
assertEquals(max, interval.getEnd().toEpochMilli());
}
final Stats stats = ds.getStatisticValue(latitudeStats);
assertEquals(20L, stats.count());
assertEquals(-90.0, stats.min(), 0.1);
assertEquals(85.0, stats.max(), 0.1);
assertEquals(-0.5, stats.mean(), 0.1);
assertEquals(53.47, stats.populationStandardDeviation(), 0.1);
final BloomFilter<CharSequence> bloomFilter = ds.getStatisticValue(latitudeBloomFilter);
boolean expectLat = true;
for (double lat = -90; lat <= 90; lat += 5) {
if (expectLat) {
assertTrue(bloomFilter.mightContain(Double.toString(lat)));
} else {
assertFalse(bloomFilter.mightContain(Double.toString(lat)));
}
// and forth each iteration, 3 times it stays true at these latitudes
if (!DoubleMath.fuzzyEquals(-40, lat, 0.1) && !DoubleMath.fuzzyEquals(25, lat, 0.1) && !DoubleMath.fuzzyEquals(80, lat, 0.1)) {
expectLat = !expectLat;
}
}
final NumericHistogram histogram = ds.getStatisticValue(latitudeHistogram);
assertEquals(20L, histogram.getTotalCount(), 0.1);
assertEquals(-90.0, histogram.getMinValue(), 0.1);
assertEquals(85.0, histogram.getMaxValue(), 0.1);
assertEquals(0.0, histogram.quantile(0.5), 0.1);
}
Aggregations