Search in sources :

Example 51 with FilteredAggregatorFactory

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

the class CalciteQueryTest method testMultipleExactCountDistinctWithGroupingAndOtherAggregators.

@Test
public void testMultipleExactCountDistinctWithGroupingAndOtherAggregators() throws Exception {
    requireMergeBuffers(4);
    testQuery(PLANNER_CONFIG_NO_HLL.withOverrides(ImmutableMap.of(PlannerConfig.CTX_KEY_USE_GROUPING_SET_FOR_EXACT_DISTINCT, "true")), "SELECT FLOOR(__time to day), COUNT(distinct city), COUNT(distinct user) FROM druid.visits GROUP BY 1", CalciteTests.REGULAR_USER_AUTH_RESULT, ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.USERVISITDATASOURCE).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "timestamp_floor(\"__time\",'P1D',null,'UTC')", ColumnType.LONG)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.LONG), new DefaultDimensionSpec("city", "d1"), new DefaultDimensionSpec("user", "d2"))).setAggregatorSpecs(aggregators(new GroupingAggregatorFactory("a0", Arrays.asList("v0", "city", "user")))).setSubtotalsSpec(ImmutableList.of(ImmutableList.of("d0", "d1"), ImmutableList.of("d0", "d2"))).setContext(withTimestampResultContext(QUERY_CONTEXT_DEFAULT, "d0", 0, Granularities.DAY)).build())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("d0", "_d0", ColumnType.LONG))).setAggregatorSpecs(aggregators(new FilteredAggregatorFactory(new CountAggregatorFactory("_a0"), and(not(selector("d1", null, null)), selector("a0", "1", null))), new FilteredAggregatorFactory(new CountAggregatorFactory("_a1"), and(not(selector("d2", null, null)), selector("a0", "2", null))))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1609459200000L, 3L, 2L }, new Object[] { 1609545600000L, 3L, 4L }, new Object[] { 1609632000000L, 1L, 1L }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) GroupingAggregatorFactory(org.apache.druid.query.aggregation.GroupingAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 52 with FilteredAggregatorFactory

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

the class CalciteQueryTest method testStringAggExpression.

@Test
public void testStringAggExpression() throws Exception {
    cannotVectorize();
    testQuery("SELECT STRING_AGG(DISTINCT CONCAT(dim1, dim2), ','), STRING_AGG(DISTINCT CONCAT(dim1, dim2), CONCAT('|', '|')) FROM foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).virtualColumns(expressionVirtualColumn("v0", "concat(\"dim1\",\"dim2\")", ColumnType.STRING)).aggregators(aggregators(new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a0", ImmutableSet.of("v0"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"v0\")", "array_set_add_all(\"__acc\", \"a0\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("v0", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a1", ImmutableSet.of("v0"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"v0\")", "array_set_add_all(\"__acc\", \"a1\")", null, "if(array_length(o) == 0, null, array_to_string(o, '||'))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("v0", null, null))))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(useDefault ? new Object[] { "10.1,1a,2,a,abc,defabc", "10.1||1a||2||a||abc||defabc" } : new Object[] { "1a,2,a,defabc", "1a||2||a||defabc" }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) Test(org.junit.Test)

Example 53 with FilteredAggregatorFactory

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

the class CalciteQueryTest method testStringAggMultiValue.

@Test
public void testStringAggMultiValue() throws Exception {
    cannotVectorize();
    testQuery("SELECT STRING_AGG(dim3, ','), STRING_AGG(DISTINCT dim3, ',') FROM foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(aggregators(new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a0", ImmutableSet.of("dim3"), "__acc", "[]", "[]", true, false, false, "array_append(\"__acc\", \"dim3\")", "array_concat(\"__acc\", \"a0\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("dim3", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a1", ImmutableSet.of("dim3"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"dim3\")", "array_set_add_all(\"__acc\", \"a1\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("dim3", null, null))))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(useDefault ? new Object[] { "a,b,b,c,d", "a,b,c,d" } : new Object[] { "a,b,b,c,d,", ",a,b,c,d" }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) Test(org.junit.Test)

Example 54 with FilteredAggregatorFactory

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

the class CalciteQueryTest method testBitwiseAggregatorsGroupBy.

@Test
public void testBitwiseAggregatorsGroupBy() throws Exception {
    cannotVectorize();
    testQuery("SELECT\n" + " dim2,\n" + " BIT_AND(l1),\n" + " BIT_OR(l1),\n" + " BIT_XOR(l1)\n" + "FROM druid.numfoo GROUP BY 1 ORDER BY 4", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim2", "_d0", ColumnType.STRING)).setAggregatorSpecs(aggregators(new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a0", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseAnd(\"__acc\", \"l1\")", "bitwiseAnd(\"__acc\", \"a0\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a1", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseOr(\"__acc\", \"l1\")", "bitwiseOr(\"__acc\", \"a1\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a2", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseXor(\"__acc\", \"l1\")", "bitwiseXor(\"__acc\", \"a2\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))))).setLimitSpec(DefaultLimitSpec.builder().orderBy(new OrderByColumnSpec("a2", Direction.ASCENDING, StringComparators.NUMERIC)).build()).setContext(QUERY_CONTEXT_DEFAULT).build()), useDefault ? ImmutableList.of(new Object[] { "abc", 0L, 0L, 0L }, new Object[] { "a", 0L, 7L, 7L }, new Object[] { "", 0L, 325323L, 325323L }) : ImmutableList.of(new Object[] { "abc", null, null, null }, new Object[] { "", 0L, 0L, 0L }, new Object[] { "a", 0L, 7L, 7L }, new Object[] { null, 0L, 325323L, 325323L }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 55 with FilteredAggregatorFactory

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

the class CalciteQueryTest method testStringAggNumeric.

@Test
public void testStringAggNumeric() throws Exception {
    cannotVectorize();
    testQuery("SELECT STRING_AGG(l1, ','), STRING_AGG(DISTINCT l1, ','), STRING_AGG(d1, ','), STRING_AGG(DISTINCT d1, ','), STRING_AGG(f1, ','), STRING_AGG(DISTINCT f1, ',') FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(aggregators(new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a0", ImmutableSet.of("l1"), "__acc", "[]", "[]", true, false, false, "array_append(\"__acc\", \"l1\")", "array_concat(\"__acc\", \"a0\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a1", ImmutableSet.of("l1"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"l1\")", "array_set_add_all(\"__acc\", \"a1\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a2", ImmutableSet.of("d1"), "__acc", "[]", "[]", true, false, false, "array_append(\"__acc\", \"d1\")", "array_concat(\"__acc\", \"a2\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("d1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a3", ImmutableSet.of("d1"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"d1\")", "array_set_add_all(\"__acc\", \"a3\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("d1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a4", ImmutableSet.of("f1"), "__acc", "[]", "[]", true, false, false, "array_append(\"__acc\", \"f1\")", "array_concat(\"__acc\", \"a4\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("f1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a5", ImmutableSet.of("f1"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"f1\")", "array_set_add_all(\"__acc\", \"a5\")", null, "if(array_length(o) == 0, null, array_to_string(o, ','))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("f1", null, null))))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(useDefault ? new Object[] { "7,325323,0,0,0,0", "0,325323,7", "1.0,1.7,0.0,0.0,0.0,0.0", "0.0,1.0,1.7", "1.0,0.10000000149011612,0.0,0.0,0.0,0.0", "0.0,0.10000000149011612,1.0" } : new Object[] { "7,325323,0", "0,325323,7", "1.0,1.7,0.0", "0.0,1.0,1.7", "1.0,0.10000000149011612,0.0", "0.0,0.10000000149011612,1.0" }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) Test(org.junit.Test)

Aggregations

FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)63 Test (org.junit.Test)52 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)28 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)23 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)23 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)20 QueryDataSource (org.apache.druid.query.QueryDataSource)14 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)14 ExpressionLambdaAggregatorFactory (org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory)13 NotDimFilter (org.apache.druid.query.filter.NotDimFilter)11 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)10 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)10 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)8 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)8 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)8 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)8 Result (org.apache.druid.query.Result)7 LongMaxAggregatorFactory (org.apache.druid.query.aggregation.LongMaxAggregatorFactory)7 TableDataSource (org.apache.druid.query.TableDataSource)6 DimFilter (org.apache.druid.query.filter.DimFilter)6