use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class SketchSetPostAggregatorTest method testToString.
@Test
public void testToString() {
final PostAggregator postAgg = new SketchSetPostAggregator("summary", "UNION", null, Arrays.asList(new FieldAccessPostAggregator("field1", "sketch"), new FieldAccessPostAggregator("field2", "sketch")));
Assert.assertEquals("SketchSetPostAggregator{name='summary', fields=[FieldAccessPostAggregator{name='field1', fieldName='sketch'}, FieldAccessPostAggregator{name='field2', fieldName='sketch'}], func=UNION, size=16384}", postAgg.toString());
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class SketchToStringPostAggregatorTest 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);
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();
EasyMock.replay(field1, field2);
SketchToStringPostAggregator postAgg1 = new SketchToStringPostAggregator("summary", field1);
SketchToStringPostAggregator postAgg2 = new SketchToStringPostAggregator("summary", field2);
String summary1 = (String) postAgg1.compute(ImmutableMap.of());
String summary2 = (String) postAgg2.compute(ImmutableMap.of());
Assert.assertEquals(0, postAgg1.getComparator().compare(summary1, summary2));
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class SketchToStringPostAggregatorTest method testSerde.
@Test
public void testSerde() throws JsonProcessingException {
final PostAggregator there = new SketchToStringPostAggregator("summary", new FieldAccessPostAggregator("field", "sketch"));
DefaultObjectMapper mapper = new DefaultObjectMapper();
SketchToStringPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), SketchToStringPostAggregator.class);
Assert.assertEquals(there, andBackAgain);
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchTTestPostAggregatorTest method testComputeMismatchedSketches.
@Test
public void testComputeMismatchedSketches() {
expectedException.expect(IAE.class);
expectedException.expectMessage("Sketches have different number of values: 2 and 100");
ArrayOfDoublesUpdatableSketch s1 = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16).setNumberOfValues(2).build();
ArrayOfDoublesUpdatableSketch s2 = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16).setNumberOfValues(100).build();
PostAggregator field1 = EasyMock.createMock(PostAggregator.class);
EasyMock.expect(field1.compute(EasyMock.anyObject(Map.class))).andReturn(s1).anyTimes();
PostAggregator field2 = EasyMock.createMock(PostAggregator.class);
EasyMock.expect(field2.compute(EasyMock.anyObject(Map.class))).andReturn(s2).anyTimes();
EasyMock.replay(field1, field2);
new ArrayOfDoublesSketchTTestPostAggregator("a", Arrays.asList(field1, field2)).compute(ImmutableMap.of());
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchToEstimatePostAggregatorTest method testSerde.
@Test
public void testSerde() throws JsonProcessingException {
final PostAggregator there = new ArrayOfDoublesSketchToEstimatePostAggregator("a", new ConstantPostAggregator("", 0));
DefaultObjectMapper mapper = new DefaultObjectMapper();
ArrayOfDoublesSketchToEstimatePostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), ArrayOfDoublesSketchToEstimatePostAggregator.class);
Assert.assertEquals(there, andBackAgain);
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
}
Aggregations