Search in sources :

Example 31 with CountAggregatorFactory

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

the class CalciteJoinQueryTest method testCommaJoinTableLookupTableMismatchedTypes.

// This SQL currently does not result in an optimum plan.
// Unfortunately, we have disabled pushing down predicates (conditions and filters) due to https://github.com/apache/druid/pull/9773
// Hence, comma join will result in a cross join with filter on outermost
@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testCommaJoinTableLookupTableMismatchedTypes(Map<String, Object> queryContext) throws Exception {
    // Regression test for https://github.com/apache/druid/issues/9646.
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT COUNT(*)\n" + "FROM foo, lookup.lookyloo l, numfoo\n" + "WHERE foo.cnt = l.k AND l.k = numfoo.cnt\n", queryContext, ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(join(join(new TableDataSource(CalciteTests.DATASOURCE1), new LookupDataSource("lookyloo"), "j0.", "1", JoinType.INNER), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).columns("cnt").context(QUERY_CONTEXT_DEFAULT).build()), "_j0.", "1", JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new CountAggregatorFactory("a0")).filters(and(expressionFilter("(\"cnt\" == CAST(\"j0.k\", 'LONG'))"), expressionFilter("(CAST(\"j0.k\", 'LONG') == \"_j0.cnt\")"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 0L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LookupDataSource(org.apache.druid.query.LookupDataSource) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 32 with CountAggregatorFactory

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

the class CalciteJoinQueryTest method testJoinTableLookupTableMismatchedTypesWithoutComma.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testJoinTableLookupTableMismatchedTypesWithoutComma(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT COUNT(*)\n" + "FROM foo\n" + "INNER JOIN lookup.lookyloo l ON foo.cnt = l.k\n" + "INNER JOIN numfoo ON l.k = numfoo.cnt\n", queryContext, ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(join(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(newScanQueryBuilder().dataSource(new LookupDataSource("lookyloo")).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("v0", "CAST(\"k\", 'LONG')", ColumnType.LONG)).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).columns("k", "v0").context(queryContext).build()), "j0.", equalsCondition(DruidExpression.ofColumn(ColumnType.LONG, "cnt"), DruidExpression.ofColumn(ColumnType.LONG, "j0.v0")), JoinType.INNER), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).columns("cnt").context(queryContext).build()), "_j0.", equalsCondition(makeExpression(ColumnType.LONG, "CAST(\"j0.k\", 'LONG')"), DruidExpression.ofColumn(ColumnType.LONG, "_j0.cnt")), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new CountAggregatorFactory("a0")).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 0L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LookupDataSource(org.apache.druid.query.LookupDataSource) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 33 with CountAggregatorFactory

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

the class CalciteJoinQueryTest method testNotInAggregationSubquery.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testNotInAggregationSubquery(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT DISTINCT __time FROM druid.foo WHERE __time NOT IN (SELECT MAX(__time) FROM druid.foo)", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new LongMaxAggregatorFactory("a0", "__time")).context(QUERY_CONTEXT_DEFAULT).build()).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(new CountAggregatorFactory("_a0"), NullHandling.sqlCompatible() ? new FilteredAggregatorFactory(new CountAggregatorFactory("_a1"), not(selector("a0", null, null))) : new CountAggregatorFactory("_a1")).setContext(queryContext).build()), "j0.", "1", JoinType.INNER), new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new LongMaxAggregatorFactory("a0", "__time")).postAggregators(expressionPostAgg("p0", "1")).context(QUERY_CONTEXT_DEFAULT).build()), "_j0.", "(\"__time\" == \"_j0.a0\")", JoinType.LEFT)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(or(selector("j0._a0", "0", null), and(selector("_j0.p0", null, null), expressionFilter("(\"j0._a1\" >= \"j0._a0\")")))).setDimensions(dimensions(new DefaultDimensionSpec("__time", "d0", ColumnType.LONG))).setContext(queryContext).build()), ImmutableList.of(new Object[] { timestamp("2000-01-01") }, new Object[] { timestamp("2000-01-02") }, new Object[] { timestamp("2000-01-03") }, new Object[] { timestamp("2001-01-01") }, new Object[] { timestamp("2001-01-02") }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LongMaxAggregatorFactory(org.apache.druid.query.aggregation.LongMaxAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 34 with CountAggregatorFactory

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

the class CalciteJoinQueryTest method testJoinWithLimitBeforeJoining.

@Test
public void testJoinWithLimitBeforeJoining() throws Exception {
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT t1.dim2, AVG(t1.m2) FROM (SELECT * FROM foo LIMIT 10) AS t1 INNER JOIN foo AS t2 ON t1.m1 = t2.m1 GROUP BY t1.dim2", ImmutableList.of(GroupByQuery.builder().setDataSource(join(new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).columns("dim2", "m1", "m2").context(QUERY_CONTEXT_DEFAULT).limit(10).build()), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).columns(ImmutableList.of("m1")).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(DruidExpression.ofColumn(ColumnType.FLOAT, "m1"), DruidExpression.ofColumn(ColumnType.FLOAT, "j0.m1")), JoinType.INNER)).setInterval(querySegmentSpec(Filtration.eternity())).setDimensions(new DefaultDimensionSpec("dim2", "d0", ColumnType.STRING)).setGranularity(Granularities.ALL).setAggregatorSpecs(useDefault ? aggregators(new DoubleSumAggregatorFactory("a0:sum", "m2"), new CountAggregatorFactory("a0:count")) : aggregators(new DoubleSumAggregatorFactory("a0:sum", "m2"), new FilteredAggregatorFactory(new CountAggregatorFactory("a0:count"), not(selector("m2", 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()), NullHandling.sqlCompatible() ? ImmutableList.of(new Object[] { null, 4.0 }, new Object[] { "", 3.0 }, new Object[] { "a", 2.5 }, new Object[] { "abc", 5.0 }) : ImmutableList.of(new Object[] { "", 3.6666666666666665 }, new Object[] { "a", 2.5 }, new Object[] { "abc", 5.0 }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) ArithmeticPostAggregator(org.apache.druid.query.aggregation.post.ArithmeticPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) QueryDataSource(org.apache.druid.query.QueryDataSource) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 35 with CountAggregatorFactory

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

the class CalciteJoinQueryTest method testFilterAndGroupByLookupUsingJoinOperatorWithValueFilterPushdownMatchesNothig.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testFilterAndGroupByLookupUsingJoinOperatorWithValueFilterPushdownMatchesNothig(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT lookyloo.k, COUNT(*)\n" + "FROM foo LEFT JOIN lookup.lookyloo ON foo.dim2 = lookyloo.k\n" + "WHERE lookyloo.v = '123'\n" + "GROUP BY lookyloo.k", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new LookupDataSource("lookyloo"), "j0.", equalsCondition(makeColumnExpression("dim2"), makeColumnExpression("j0.k")), JoinType.LEFT)).setInterval(querySegmentSpec(Filtration.eternity())).setDimFilter(selector("j0.v", "123", null)).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("j0.k", "d0"))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(queryContext).build()), ImmutableList.of());
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)300 Test (org.junit.Test)249 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)103 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)81 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)62 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)50 TableDataSource (org.apache.druid.query.TableDataSource)44 QueryDataSource (org.apache.druid.query.QueryDataSource)41 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)40 GroupByQuery (org.apache.druid.query.groupby.GroupByQuery)37 Result (org.apache.druid.query.Result)36 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)35 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)30 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)30 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)28 IncrementalIndexSegment (org.apache.druid.segment.IncrementalIndexSegment)27 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)26 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)26 IncrementalIndex (org.apache.druid.segment.incremental.IncrementalIndex)26 Parameters (junitparams.Parameters)24