Search in sources :

Example 56 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class SketchSetPostAggregatorTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    List<PostAggregator> fields = Arrays.asList(new FieldAccessPostAggregator("field1", "sketch"), new FieldAccessPostAggregator("field2", "sketch"));
    final PostAggregator union = new SketchSetPostAggregator("summary", "UNION", null, fields);
    final PostAggregator intersect = new SketchSetPostAggregator("summary", "INTERSECT", null, fields);
    final PostAggregator not = new SketchSetPostAggregator("summary", "NOT", null, fields);
    List<PostAggregator> serdeTests = Arrays.asList(union, intersect, not);
    for (PostAggregator there : serdeTests) {
        DefaultObjectMapper mapper = new DefaultObjectMapper();
        SketchSetPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), SketchSetPostAggregator.class);
        Assert.assertEquals(there, andBackAgain);
        Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
    }
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 57 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator 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());
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) Test(org.junit.Test)

Example 58 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator 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());
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 59 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class ThetaSketchSqlAggregatorTest method testThetaSketchPostAggs.

@Test
public void testThetaSketchPostAggs() throws Exception {
    final List<Object[]> expectedResults;
    if (NullHandling.replaceWithDefault()) {
        expectedResults = ImmutableList.of(new Object[] { 6L, 2.0d, 3.0d, "{\"estimate\":2.0,\"highBound\":2.0,\"lowBound\":2.0,\"numStdDev\":10}", "\"AQMDAAA6zJOQxkPsNomrZQ==\"", "\"AgMDAAAazJMGAAAAAACAP1XTBztMIcMJ+HOoBBne1zKQxkPsNomrZUeWbJt3n+VpF8EdUoUHAXvxsLkOSE0lfQ==\"", "\"AQMDAAA6zJMXwR1ShQcBew==\"", "\"AQMDAAA6zJOQxkPsNomrZQ==\"", 1.0d });
    } else {
        expectedResults = ImmutableList.of(new Object[] { 6L, 2.0d, 3.0d, "{\"estimate\":2.0,\"highBound\":2.0,\"lowBound\":2.0,\"numStdDev\":10}", "\"AQMDAAA6zJOQxkPsNomrZQ==\"", "\"AgMDAAAazJMGAAAAAACAP1XTBztMIcMJ+HOoBBne1zKQxkPsNomrZUeWbJt3n+VpF8EdUoUHAXvxsLkOSE0lfQ==\"", "\"AQMDAAA6zJMXwR1ShQcBew==\"", "\"AQMDAAA6zJOQxkPsNomrZQ==\"", 1.0d });
    }
    testQuery("SELECT\n" + "  SUM(cnt),\n" + "  theta_sketch_estimate(DS_THETA(dim2)),\n" + "  theta_sketch_estimate(DS_THETA(CONCAT(dim2, 'hello'))),\n" + "  theta_sketch_estimate_with_error_bounds(DS_THETA(dim2), 10),\n" + "  THETA_SKETCH_INTERSECT(DS_THETA(dim2), DS_THETA(dim1)),\n" + "  THETA_SKETCH_UNION(DS_THETA(dim2), DS_THETA(dim1)),\n" + "  THETA_SKETCH_NOT(DS_THETA(dim2), DS_THETA(dim1)),\n" + "  THETA_SKETCH_INTERSECT(32768, DS_THETA(dim2), DS_THETA(dim1)),\n" + "  theta_sketch_estimate(THETA_SKETCH_INTERSECT(THETA_SKETCH_INTERSECT(DS_THETA(dim2), DS_THETA(dim1)), DS_THETA(dim2)))\n" + "FROM druid.foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).virtualColumns(new ExpressionVirtualColumn("v0", "concat(\"dim2\",'hello')", ColumnType.STRING, TestExprMacroTable.INSTANCE)).aggregators(ImmutableList.of(new LongSumAggregatorFactory("a0", "cnt"), new SketchMergeAggregatorFactory("a1", "dim2", null, null, null, null), new SketchMergeAggregatorFactory("a2", "v0", null, null, null, null), new SketchMergeAggregatorFactory("a3", "dim1", null, null, null, null))).postAggregators(new SketchEstimatePostAggregator("p1", new FieldAccessPostAggregator("p0", "a1"), null), new SketchEstimatePostAggregator("p3", new FieldAccessPostAggregator("p2", "a2"), null), new SketchEstimatePostAggregator("p5", new FieldAccessPostAggregator("p4", "a1"), 10), new SketchSetPostAggregator("p8", "INTERSECT", null, ImmutableList.of(new FieldAccessPostAggregator("p6", "a1"), new FieldAccessPostAggregator("p7", "a3"))), new SketchSetPostAggregator("p11", "UNION", null, ImmutableList.of(new FieldAccessPostAggregator("p9", "a1"), new FieldAccessPostAggregator("p10", "a3"))), new SketchSetPostAggregator("p14", "NOT", null, ImmutableList.of(new FieldAccessPostAggregator("p12", "a1"), new FieldAccessPostAggregator("p13", "a3"))), new SketchSetPostAggregator("p17", "INTERSECT", 32768, ImmutableList.of(new FieldAccessPostAggregator("p15", "a1"), new FieldAccessPostAggregator("p16", "a3"))), new SketchEstimatePostAggregator("p23", new SketchSetPostAggregator("p22", "INTERSECT", null, ImmutableList.of(new SketchSetPostAggregator("p20", "INTERSECT", null, ImmutableList.of(new FieldAccessPostAggregator("p18", "a1"), new FieldAccessPostAggregator("p19", "a3"))), new FieldAccessPostAggregator("p21", "a1"))), null)).context(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
Also used : SketchMergeAggregatorFactory(org.apache.druid.query.aggregation.datasketches.theta.SketchMergeAggregatorFactory) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) SketchSetPostAggregator(org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) SketchEstimatePostAggregator(org.apache.druid.query.aggregation.datasketches.theta.SketchEstimatePostAggregator) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 60 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class ThetaSketchSqlAggregatorTest method testAvgDailyCountDistinctThetaSketch.

@Test
public void testAvgDailyCountDistinctThetaSketch() throws Exception {
    // Can't vectorize due to outer query (it operates on an inlined data source, which cannot be vectorized).
    cannotVectorize();
    final List<Object[]> expectedResults = ImmutableList.of(new Object[] { 1L });
    testQuery("SELECT\n" + "  AVG(u)\n" + "FROM (SELECT FLOOR(__time TO DAY), APPROX_COUNT_DISTINCT_DS_THETA(cnt) AS u FROM druid.foo GROUP BY 1)", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(new PeriodGranularity(Period.days(1), null, DateTimeZone.UTC)).aggregators(Collections.singletonList(new SketchMergeAggregatorFactory("a0:a", "cnt", null, null, null, null))).postAggregators(ImmutableList.of(new FinalizingFieldAccessPostAggregator("a0", "a0:a"))).context(TIMESERIES_CONTEXT_BY_GRAN).build().withOverriddenContext(BaseCalciteQueryTest.getTimeseriesContextWithFloorTime(TIMESERIES_CONTEXT_BY_GRAN, "d0")))).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setAggregatorSpecs(NullHandling.replaceWithDefault() ? Arrays.asList(new LongSumAggregatorFactory("_a0:sum", "a0"), new CountAggregatorFactory("_a0:count")) : Arrays.asList(new LongSumAggregatorFactory("_a0:sum", "a0"), new FilteredAggregatorFactory(new CountAggregatorFactory("_a0:count"), BaseCalciteQueryTest.not(BaseCalciteQueryTest.selector("a0", null, null))))).setPostAggregatorSpecs(ImmutableList.of(new ArithmeticPostAggregator("_a0", "quotient", ImmutableList.of(new FieldAccessPostAggregator(null, "_a0:sum"), new FieldAccessPostAggregator(null, "_a0:count"))))).setContext(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) SketchMergeAggregatorFactory(org.apache.druid.query.aggregation.datasketches.theta.SketchMergeAggregatorFactory) ArithmeticPostAggregator(org.apache.druid.query.aggregation.post.ArithmeticPostAggregator) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Aggregations

FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)108 Test (org.junit.Test)97 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)45 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)32 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)30 FinalizingFieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator)24 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)22 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)22 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)17 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)17 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)15 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)15 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)14 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)12 HashMap (java.util.HashMap)11 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)11 QueryDataSource (org.apache.druid.query.QueryDataSource)10 Aggregator (org.apache.druid.query.aggregation.Aggregator)10 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)10 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)10