use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchSetOpPostAggregatorTest method testComparator.
@Test
public void testComparator() {
ArrayOfDoublesUpdatableSketch s1 = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16).setNumberOfValues(2).build();
s1.update("foo", new double[] { 1.0, 2.0 });
ArrayOfDoublesUpdatableSketch s2 = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16).setNumberOfValues(2).build();
s2.update("foo", new double[] { 2.0, 2.0 });
s2.update("bar", new double[] { 3.0, 4.0 });
// duplicate
ArrayOfDoublesUpdatableSketch s3 = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16).setNumberOfValues(2).build();
s3.update("foo", new double[] { 1.0, 2.0 });
ArrayOfDoublesUpdatableSketch s4 = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16).setNumberOfValues(2).build();
s4.update("foo", new double[] { 2.0, 2.0 });
s4.update("bar", new double[] { 3.0, 4.0 });
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();
PostAggregator field3 = EasyMock.createMock(PostAggregator.class);
EasyMock.expect(field3.compute(EasyMock.anyObject(Map.class))).andReturn(s3).anyTimes();
PostAggregator field4 = EasyMock.createMock(PostAggregator.class);
EasyMock.expect(field4.compute(EasyMock.anyObject(Map.class))).andReturn(s4).anyTimes();
EasyMock.replay(field1, field2, field3, field4);
final ArrayOfDoublesSketchSetOpPostAggregator postAgg1 = new ArrayOfDoublesSketchSetOpPostAggregator("a", "UNION", 16, 2, ImmutableList.of(field1, field2));
final ArrayOfDoublesSketchSetOpPostAggregator postAgg2 = new ArrayOfDoublesSketchSetOpPostAggregator("a", "UNION", 16, 2, ImmutableList.of(field3, field4));
Comparator comparator = postAgg1.getComparator();
ArrayOfDoublesSketch sketch1 = postAgg1.compute(ImmutableMap.of());
ArrayOfDoublesSketch sketch2 = postAgg2.compute(ImmutableMap.of());
// comparator compares value of each sketches estimate so should be identical
Assert.assertEquals(0, comparator.compare(sketch1, sketch2));
Assert.assertEquals(0, Double.compare(sketch1.getEstimate(), sketch2.getEstimate()));
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchSetOpPostAggregatorTest method testConstructorNumArgs.
@Test
public void testConstructorNumArgs() {
expectedException.expect(IAE.class);
expectedException.expectMessage("Illegal number of fields[0], must be > 1");
final PostAggregator there = new ArrayOfDoublesSketchSetOpPostAggregator("a", "UNION", null, null, ImmutableList.of());
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchToMeansPostAggregatorTest method testToString.
@Test
public void testToString() {
PostAggregator postAgg = new ArrayOfDoublesSketchToMeansPostAggregator("a", new ConstantPostAggregator("", 0));
Assert.assertEquals("ArrayOfDoublesSketchToMeansPostAggregator{name='a', field=ConstantPostAggregator{name='', constantValue=0}}", postAgg.toString());
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchToMeansPostAggregatorTest method testSerde.
@Test
public void testSerde() throws JsonProcessingException {
final PostAggregator there = new ArrayOfDoublesSketchToMeansPostAggregator("a", new ConstantPostAggregator("", 0));
DefaultObjectMapper mapper = new DefaultObjectMapper();
ArrayOfDoublesSketchToMeansPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), ArrayOfDoublesSketchToMeansPostAggregator.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 ArrayOfDoublesSketchToMeansPostAggregatorTest method testComparator.
@Test
public void testComparator() {
expectedException.expect(IAE.class);
expectedException.expectMessage("Comparing arrays of mean values is not supported");
final PostAggregator postAgg = new ArrayOfDoublesSketchToMeansPostAggregator("a", new ConstantPostAggregator("", 0));
postAgg.getComparator();
}
Aggregations