maytasm commented on code in PR #16564:
URL: https://github.com/apache/druid/pull/16564#discussion_r1690481001
##########
extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java:
##########
@@ -716,6 +730,59 @@ public void testPercentilePostAggregator() throws Exception
}
}
+ @Test
+ public void testBuildingAndCountingHistogramsIncrementalIndex() throws
Exception
+ {
+ List<String> dimensions = Collections.singletonList("d");
+ int n = 10;
+ DateTime startOfDay = DateTimes.of("2000-01-01");
+ List<InputRow> inputRows = new ArrayList<>(n);
+ for (int i = 1; i <= n; i++) {
+ String val = String.valueOf(i * 1.0d);
+
+ inputRows.add(new MapBasedInputRow(
+ startOfDay.plusMinutes(i),
+ dimensions,
+ ImmutableMap.of("x", i, "d", val)
+ ));
+ }
+
+ IncrementalIndex index = AggregationTestHelper.createIncrementalIndex(
+ inputRows.iterator(),
+ new NoopInputRowParser(null),
+ new AggregatorFactory[]{
+ new CountAggregatorFactory("count"),
+ new SpectatorHistogramAggregatorFactory("histogram", "x")
+ },
+ 0,
+ Granularities.NONE,
+ 100,
+ false
+ );
+
+ ImmutableList<Segment> segments = ImmutableList.of(
+ new IncrementalIndexSegment(index, SegmentId.dummy("test")),
+ helper.persistIncrementalIndex(index, null)
+ );
+
+ GroupByQuery query = new GroupByQuery.Builder()
+ .setDataSource("test")
+ .setGranularity(Granularities.HOUR)
+ .setInterval("1970/2050")
+ .setAggregatorSpecs(
+ new DoubleSumAggregatorFactory("doubleSum", "histogram")
+ ).build();
+
+ Sequence<ResultRow> seq = helper.runQueryOnSegmentsObjs(segments, query);
+
+ List<ResultRow> results = seq.toList();
+ Assert.assertEquals(1, results.size());
+ // Check timestamp
+ Assert.assertEquals(startOfDay.getMillis(), results.get(0).get(0));
+ // Check doubleSum
+ Assert.assertEquals(n * segments.size(), (Double) results.get(0).get(1),
0.001);
Review Comment:
I think it's fine to have both the in-memory and the persisted indexes in
the test. This way we can test when the query hit both type of indexes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]