use of org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchAggregatorFactoryTest method testResultArraySignature.
@Test
public void testResultArraySignature() {
final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new CountAggregatorFactory("count"), new ArrayOfDoublesSketchAggregatorFactory("arrayOfDoublesSketch", "col", 1, ImmutableList.of("met"), 1)).postAggregators(new FieldAccessPostAggregator("a", "arrayOfDoublesSketch"), new FinalizingFieldAccessPostAggregator("b", "arrayOfDoublesSketch")).build();
Assert.assertEquals(RowSignature.builder().addTimeColumn().add("count", ColumnType.LONG).add("arrayOfDoublesSketch", null).add("a", ArrayOfDoublesSketchModule.BUILD_TYPE).add("b", ColumnType.DOUBLE).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
use of org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator in project druid by druid-io.
the class TopNQueryQueryToolChestTest method doTestCacheStrategyOrderByPost.
private void doTestCacheStrategyOrderByPost(final ColumnType valueType, final Object dimValue) throws IOException {
CacheStrategy<Result<TopNResultValue>, Object, TopNQuery> strategy = new TopNQueryQueryToolChest(null, null).getCacheStrategy(new TopNQuery(new TableDataSource("dummy"), VirtualColumns.EMPTY, new DefaultDimensionSpec("test", "test", valueType), new NumericTopNMetricSpec("post"), 3, new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2015-01-01/2015-01-02"))), null, Granularities.ALL, ImmutableList.of(new HyperUniquesAggregatorFactory("metric1", "test", false, false), new CountAggregatorFactory("metric2")), ImmutableList.of(new ArithmeticPostAggregator("post", "+", ImmutableList.of(new FinalizingFieldAccessPostAggregator("metric1", "metric1"), new FieldAccessPostAggregator("metric2", "metric2")))), null));
HyperLogLogCollector collector = getIntermediateHllCollector(valueType.getType(), dimValue);
final Result<TopNResultValue> result1 = new Result<>(// test timestamps that result in integer size millis
DateTimes.utc(123L), new TopNResultValue(Collections.singletonList(ImmutableMap.of("test", dimValue, "metric1", collector, "metric2", 2, "post", collector.estimateCardinality() + 2))));
Object preparedValue = strategy.prepareForSegmentLevelCache().apply(result1);
ObjectMapper objectMapper = TestHelper.makeJsonMapper();
Object fromCacheValue = objectMapper.readValue(objectMapper.writeValueAsBytes(preparedValue), strategy.getCacheObjectClazz());
Result<TopNResultValue> fromCacheResult = strategy.pullFromSegmentLevelCache().apply(fromCacheValue);
Assert.assertEquals(result1, fromCacheResult);
final Result<TopNResultValue> resultLevelCacheResult = new Result<>(// test timestamps that result in integer size millis
DateTimes.utc(123L), new TopNResultValue(Collections.singletonList(ImmutableMap.of("test", dimValue, "metric1", collector.estimateCardinality(), "metric2", 2, "post", collector.estimateCardinality() + 2))));
Object preparedResultCacheValue = strategy.prepareForCache(true).apply(resultLevelCacheResult);
Object fromResultCacheValue = objectMapper.readValue(objectMapper.writeValueAsBytes(preparedResultCacheValue), strategy.getCacheObjectClazz());
Result<TopNResultValue> fromResultCacheResult = strategy.pullFromCache(true).apply(fromResultCacheValue);
Assert.assertEquals(resultLevelCacheResult, fromResultCacheResult);
}
use of org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator in project druid by druid-io.
the class ExpressionLambdaAggregatorFactoryTest method testResultArraySignature.
@Test
public void testResultArraySignature() {
final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new ExpressionLambdaAggregatorFactory("string_expr", ImmutableSet.of("some_column", "some_other_column"), null, "''", "''", null, false, false, "concat(__acc, some_column, some_other_column)", "concat(__acc, string_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0.0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + double_expr", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + long_expr", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("string_array_expr", ImmutableSet.of("some_column", "some_other_column"), null, "ARRAY<STRING>[]", "ARRAY<STRING>[]", null, true, false, "array_set_add(__acc, concat(some_column, some_other_column))", "array_set_add_all(__acc, string_array_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_array_expr", ImmutableSet.of("some_column", "some_other_column_expr"), null, "0.0", "ARRAY<DOUBLE>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, double_array)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_array_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0", "ARRAY<LONG>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, long_array_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("string_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column"), null, "''", "ARRAY<STRING>[]", null, false, false, "concat(__acc, some_column, some_other_column)", "array_set_add(__acc, string_array_expr)", null, "array_to_string(o, ';')", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column_expr"), null, "0.0", "ARRAY<DOUBLE>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, double_array)", null, "array_to_string(o, ';')", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column"), null, "0", "ARRAY<LONG>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, long_array_expr)", null, "fold((x, acc) -> x + acc, o, 0)", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("complex_expr", ImmutableSet.of("some_column"), null, "hyper_unique()", null, null, false, false, "hyper_unique_add(some_column, __acc)", "hyper_unique_add(__acc, expr_agg_name)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("complex_expr_finalized", ImmutableSet.of("some_column"), null, "hyper_unique()", null, null, false, false, "hyper_unique_add(some_column, __acc)", "hyper_unique_add(__acc, expr_agg_name)", null, "hyper_unique_estimate(o)", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE)).postAggregators(new FieldAccessPostAggregator("string-array-expr-access", "string_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("string-array-expr-finalize", "string_array_expr_finalized"), new FieldAccessPostAggregator("double-array-expr-access", "double_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("double-array-expr-finalize", "double_array_expr_finalized"), new FieldAccessPostAggregator("long-array-expr-access", "long_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("long-array-expr-finalize", "long_array_expr_finalized"), new FieldAccessPostAggregator("complex-expr-access", "complex_expr_finalized"), new FinalizingFieldAccessPostAggregator("complex-expr-finalize", "complex_expr_finalized")).build();
Assert.assertEquals(RowSignature.builder().addTimeColumn().add("string_expr", ColumnType.STRING).add("double_expr", ColumnType.DOUBLE).add("long_expr", ColumnType.LONG).add("string_array_expr", ColumnType.STRING_ARRAY).add("double_array_expr", null).add("long_array_expr", null).add("string_array_expr_finalized", ColumnType.STRING).add("double_array_expr_finalized", null).add("long_array_expr_finalized", ColumnType.LONG).add("complex_expr", HyperUniquesAggregatorFactory.TYPE).add("complex_expr_finalized", null).add("string-array-expr-access", ColumnType.STRING).add("string-array-expr-finalize", ColumnType.STRING).add("double-array-expr-access", ColumnType.DOUBLE).add("double-array-expr-finalize", ColumnType.STRING).add("long-array-expr-access", ColumnType.LONG).add("long-array-expr-finalize", ColumnType.LONG).add("complex-expr-access", HyperUniquesAggregatorFactory.TYPE).add("complex-expr-finalize", ColumnType.DOUBLE).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
use of org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator in project druid by druid-io.
the class CalciteQueryTest method testStringLatestInSubquery.
// This test the off-heap (buffer) version of the LatestAggregator (String)
@Test
public void testStringLatestInSubquery() throws Exception {
// Cannot vectorize LATEST aggregator.
skipVectorize();
testQuery("SELECT SUM(val) FROM (SELECT dim2, LATEST(dim1, 10) AS val FROM foo GROUP BY dim2)", ImmutableList.of(GroupByQuery.builder().setDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("dim2", "d0"))).setAggregatorSpecs(aggregators(new StringLastAggregatorFactory("a0:a", "dim1", null, 10))).setPostAggregatorSpecs(ImmutableList.of(new FinalizingFieldAccessPostAggregator("a0", "a0:a"))).setContext(QUERY_CONTEXT_DEFAULT).build()).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(aggregators(new DoubleSumAggregatorFactory("_a0", null, "CAST(\"a0\", 'DOUBLE')", ExprMacroTable.nil()))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { NullHandling.sqlCompatible() ? 3 : 1.0 }));
}
use of org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator in project druid by druid-io.
the class CalciteQueryTest method testPrimitiveEarliestInSubquery.
// This test the off-heap (buffer) version of the EarliestAggregator (Double/Float/Long)
@Test
public void testPrimitiveEarliestInSubquery() throws Exception {
// Cannot vectorize EARLIEST aggregator.
skipVectorize();
testQuery("SELECT SUM(val1), SUM(val2), SUM(val3) FROM (SELECT dim2, EARLIEST(m1) AS val1, EARLIEST(cnt) AS val2, EARLIEST(m2) AS val3 FROM foo GROUP BY dim2)", ImmutableList.of(GroupByQuery.builder().setDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("dim2", "d0"))).setAggregatorSpecs(aggregators(new FloatFirstAggregatorFactory("a0:a", "m1", null), new LongFirstAggregatorFactory("a1:a", "cnt", null), new DoubleFirstAggregatorFactory("a2:a", "m2", null))).setPostAggregatorSpecs(ImmutableList.of(new FinalizingFieldAccessPostAggregator("a0", "a0:a"), new FinalizingFieldAccessPostAggregator("a1", "a1:a"), new FinalizingFieldAccessPostAggregator("a2", "a2:a"))).setContext(QUERY_CONTEXT_DEFAULT).build()).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(aggregators(new DoubleSumAggregatorFactory("_a0", "a0"), new LongSumAggregatorFactory("_a1", "a1"), new DoubleSumAggregatorFactory("_a2", "a2"))).setContext(QUERY_CONTEXT_DEFAULT).build()), NullHandling.sqlCompatible() ? ImmutableList.of(new Object[] { 11.0, 4L, 11.0 }) : ImmutableList.of(new Object[] { 8.0, 3L, 8.0 }));
}
Aggregations