loquisgon commented on a change in pull request #10685:
URL: https://github.com/apache/druid/pull/10685#discussion_r548072812
##########
File path:
processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/LimitedBufferHashGrouperTest.java
##########
@@ -193,6 +194,65 @@ public void testMinBufferSize()
Assert.assertEquals(expected, Lists.newArrayList(grouper.iterator(true)));
}
+ @Test
+ public void testIteratorIsReusable()
+ {
+ final int limit = 100;
+ final int keyBase = 100000;
+ final TestColumnSelectorFactory columnSelectorFactory =
GrouperTestUtil.newColumnSelectorFactory();
+ final LimitedBufferHashGrouper<Integer> grouper =
makeGrouper(columnSelectorFactory, 12120, 2, limit);
+ final int numRows = 1000;
+
+ columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("value",
10L)));
+ for (int i = 0; i < numRows; i++) {
+ Assert.assertTrue(String.valueOf(i + keyBase), grouper.aggregate(i +
keyBase).isOk());
+ }
+
+ // With minimum buffer size, after the first swap, every new key added
will result in a swap
+ if (NullHandling.replaceWithDefault()) {
+ Assert.assertEquals(224, grouper.getGrowthCount());
+ Assert.assertEquals(104, grouper.getSize());
+ Assert.assertEquals(209, grouper.getBuckets());
+ Assert.assertEquals(104, grouper.getMaxSize());
+ } else {
+ Assert.assertEquals(899, grouper.getGrowthCount());
+ Assert.assertEquals(101, grouper.getSize());
+ Assert.assertEquals(202, grouper.getBuckets());
+ Assert.assertEquals(101, grouper.getMaxSize());
+ }
+ Assert.assertEquals(100, grouper.getLimit());
+
+ // Aggregate slightly different row
+ // Since these keys are smaller, they will evict the previous 100 top
entries
+ // First 100 of these new rows will be the expected results.
+ columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("value",
11L)));
+ for (int i = 0; i < numRows; i++) {
+ Assert.assertTrue(String.valueOf(i), grouper.aggregate(i).isOk());
+ }
+ if (NullHandling.replaceWithDefault()) {
+ Assert.assertEquals(474, grouper.getGrowthCount());
+ Assert.assertEquals(104, grouper.getSize());
+ Assert.assertEquals(209, grouper.getBuckets());
+ Assert.assertEquals(104, grouper.getMaxSize());
+ } else {
+ Assert.assertEquals(1899, grouper.getGrowthCount());
+ Assert.assertEquals(101, grouper.getSize());
+ Assert.assertEquals(202, grouper.getBuckets());
+ Assert.assertEquals(101, grouper.getMaxSize());
+ }
+ Assert.assertEquals(100, grouper.getLimit());
Review comment:
It does not hurt though... i'll clean it up.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]