use of org.apache.datasketches.theta.UpdateSketch in project druid by druid-io.
the class BufferHashGrouperUsingSketchMergeAggregatorFactoryTest method testGrowingBufferGrouper.
@Test
public void testGrowingBufferGrouper() {
final TestColumnSelectorFactory columnSelectorFactory = GrouperTestUtil.newColumnSelectorFactory();
final Grouper<Integer> grouper = makeGrouper(columnSelectorFactory, 100000, 2);
try {
final int expectedMaxSize = 5;
SketchHolder sketchHolder = SketchHolder.of(Sketches.updateSketchBuilder().setNominalEntries(16).build());
UpdateSketch updateSketch = (UpdateSketch) sketchHolder.getSketch();
updateSketch.update(1);
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("sketch", sketchHolder)));
for (int i = 0; i < expectedMaxSize; i++) {
Assert.assertTrue(String.valueOf(i), grouper.aggregate(i).isOk());
}
updateSketch.update(3);
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("sketch", sketchHolder)));
for (int i = 0; i < expectedMaxSize; i++) {
Assert.assertTrue(String.valueOf(i), grouper.aggregate(i).isOk());
}
Object[] holders = Lists.newArrayList(grouper.iterator(true)).get(0).getValues();
Assert.assertEquals(2.0d, ((SketchHolder) holders[0]).getEstimate(), 0);
} finally {
grouper.close();
}
}
Aggregations