Search in sources :

Example 11 with Union

use of org.apache.datasketches.theta.Union in project druid by druid-io.

the class SketchSetPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    Union u1 = (Union) SetOperation.builder().setNominalEntries(10).build(Family.UNION);
    u1.update(10L);
    Union u2 = (Union) SetOperation.builder().setNominalEntries(10).build(Family.UNION);
    u2.update(20L);
    Union u3 = (Union) SetOperation.builder().setNominalEntries(10).build(Family.UNION);
    u3.update(10L);
    Union u4 = (Union) SetOperation.builder().setNominalEntries(10).build(Family.UNION);
    u4.update(20L);
    PostAggregator field1 = EasyMock.createMock(PostAggregator.class);
    EasyMock.expect(field1.compute(EasyMock.anyObject(Map.class))).andReturn(SketchHolder.of(u1)).anyTimes();
    PostAggregator field2 = EasyMock.createMock(PostAggregator.class);
    EasyMock.expect(field2.compute(EasyMock.anyObject(Map.class))).andReturn(SketchHolder.of(u2)).anyTimes();
    PostAggregator field3 = EasyMock.createMock(PostAggregator.class);
    EasyMock.expect(field3.compute(EasyMock.anyObject(Map.class))).andReturn(SketchHolder.of(u3)).anyTimes();
    PostAggregator field4 = EasyMock.createMock(PostAggregator.class);
    EasyMock.expect(field4.compute(EasyMock.anyObject(Map.class))).andReturn(SketchHolder.of(u4)).anyTimes();
    EasyMock.replay(field1, field2, field3, field4);
    SketchSetPostAggregator postAgg1 = new SketchSetPostAggregator("summary", "UNION", null, Arrays.asList(field1, field2));
    SketchSetPostAggregator postAgg2 = new SketchSetPostAggregator("summary", "UNION", null, Arrays.asList(field3, field4));
    SketchHolder holder1 = (SketchHolder) postAgg1.compute(ImmutableMap.of());
    SketchHolder holder2 = (SketchHolder) postAgg2.compute(ImmutableMap.of());
    Assert.assertEquals(0, postAgg1.getComparator().compare(holder1, holder2));
}
Also used : PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) Union(org.apache.datasketches.theta.Union) Test(org.junit.Test)

Aggregations

Union (org.apache.datasketches.theta.Union)11 Test (org.junit.Test)3 Sketch (org.apache.datasketches.theta.Sketch)2 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)2 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)2 WritableMemory (org.apache.datasketches.memory.WritableMemory)1 AnotB (org.apache.datasketches.theta.AnotB)1 Intersection (org.apache.datasketches.theta.Intersection)1 UpdateSketch (org.apache.datasketches.theta.UpdateSketch)1 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)1