Search in sources :

Example 21 with LookupDataSource

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

the class CalciteJoinQueryTest method testFilterAndGroupByLookupUsingJoinOperatorBackwards.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testFilterAndGroupByLookupUsingJoinOperatorBackwards(Map<String, Object> queryContext) throws Exception {
    // Like "testFilterAndGroupByLookupUsingJoinOperator", but with the table and lookup reversed.
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT lookyloo.v, COUNT(*)\n" + "FROM lookup.lookyloo RIGHT JOIN foo ON foo.dim2 = lookyloo.k\n" + "WHERE lookyloo.v <> 'xa'\n" + "GROUP BY lookyloo.v", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(new LookupDataSource("lookyloo"), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).columns("dim2").context(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(makeColumnExpression("k"), makeColumnExpression("j0.dim2")), JoinType.RIGHT)).setInterval(querySegmentSpec(Filtration.eternity())).setDimFilter(not(selector("v", "xa", null))).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("v", "d0"))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(queryContext).build()), ImmutableList.of(new Object[] { NULL_STRING, 3L }, new Object[] { "xabc", 1L }));
}
Also used : QueryDataSource(org.apache.druid.query.QueryDataSource) 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)

Example 22 with LookupDataSource

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

the class CalciteJoinQueryTest method testLeftJoinSubqueryWithNullKeyFilter.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testLeftJoinSubqueryWithNullKeyFilter(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize due to 'concat' expression.
    cannotVectorize();
    ScanQuery nullCompatibleModePlan = newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(new LookupDataSource("lookyloo")).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "concat(\"k\",'')", ColumnType.STRING)).setDimensions(new DefaultDimensionSpec("v0", "d0")).build()), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.d0")), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "j0.d0").context(queryContext).build();
    ScanQuery nonNullCompatibleModePlan = newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(new LookupDataSource("lookyloo")).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "concat(\"k\",'')", ColumnType.STRING)).setDimensions(new DefaultDimensionSpec("v0", "d0")).build()), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.d0")), JoinType.LEFT)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "j0.d0").filters(new NotDimFilter(new SelectorDimFilter("j0.d0", null, null))).context(queryContext).build();
    boolean isJoinFilterRewriteEnabled = queryContext.getOrDefault(JOIN_FILTER_REWRITE_ENABLE_KEY, true).toString().equals("true");
    testQuery("SELECT dim1, l1.k\n" + "FROM foo\n" + "LEFT JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 ON foo.dim1 = l1.k\n" + "WHERE l1.k IS NOT NULL\n", queryContext, ImmutableList.of(NullHandling.sqlCompatible() ? nullCompatibleModePlan : nonNullCompatibleModePlan), NullHandling.sqlCompatible() || !isJoinFilterRewriteEnabled ? ImmutableList.of(new Object[] { "abc", "abc" }) : ImmutableList.of(new Object[] { "10.1", "" }, // this result is incorrect. TODO : fix this result when the JoinFilterAnalyzer bug is fixed
    new Object[] { "2", "" }, new Object[] { "1", "" }, new Object[] { "def", "" }, new Object[] { "abc", "abc" }));
}
Also used : NotDimFilter(org.apache.druid.query.filter.NotDimFilter) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) LookupDataSource(org.apache.druid.query.LookupDataSource) ScanQuery(org.apache.druid.query.scan.ScanQuery) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 23 with LookupDataSource

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

the class CalciteJoinQueryTest method testInnerJoinLookupTableTableChained.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinLookupTableTableChained(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT l.k, l.v, SUM(f.m1), SUM(nf.m1)\n" + "FROM lookup.lookyloo l\n" + "INNER JOIN druid.foo f on f.dim1 = l.k\n" + "INNER JOIN druid.numfoo nf on nf.dim1 = f.dim1\n" + "GROUP BY 1, 2 ORDER BY 2", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(join(new LookupDataSource("lookyloo"), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "m1").context(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(makeColumnExpression("k"), makeColumnExpression("j0.dim1")), JoinType.INNER), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "m1").context(QUERY_CONTEXT_DEFAULT).build()), "_j0.", equalsCondition(makeColumnExpression("j0.dim1"), makeColumnExpression("_j0.dim1")), JoinType.INNER)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("k", "d0"), new DefaultDimensionSpec("v", "d1"))).setAggregatorSpecs(aggregators(new DoubleSumAggregatorFactory("a0", "j0.m1"), new DoubleSumAggregatorFactory("a1", "_j0.m1"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d1", OrderByColumnSpec.Direction.ASCENDING)), null)).setContext(queryContext).build()), ImmutableList.of(new Object[] { "abc", "xabc", 6d, 6d }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) QueryDataSource(org.apache.druid.query.QueryDataSource) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 24 with LookupDataSource

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

the class CalciteJoinQueryTest method testInnerJoinLookupTableTable.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinLookupTableTable(Map<String, Object> queryContext) throws Exception {
    // Regression test for https://github.com/apache/druid/issues/9646.
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT l.k, l.v, SUM(f.m1), SUM(nf.m1)\n" + "FROM lookup.lookyloo l\n" + "INNER JOIN druid.foo f on f.dim1 = l.k\n" + "INNER JOIN druid.numfoo nf on nf.dim1 = l.k\n" + "GROUP BY 1, 2 ORDER BY 2", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(join(new LookupDataSource("lookyloo"), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "m1").context(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(makeColumnExpression("k"), makeColumnExpression("j0.dim1")), JoinType.INNER), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "m1").context(QUERY_CONTEXT_DEFAULT).build()), "_j0.", equalsCondition(makeColumnExpression("k"), makeColumnExpression("_j0.dim1")), JoinType.INNER)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("k", "d0"), new DefaultDimensionSpec("v", "d1"))).setAggregatorSpecs(aggregators(new DoubleSumAggregatorFactory("a0", "j0.m1"), new DoubleSumAggregatorFactory("a1", "_j0.m1"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d1", OrderByColumnSpec.Direction.ASCENDING)), null)).setContext(queryContext).build()), ImmutableList.of(new Object[] { "abc", "xabc", 6d, 6d }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) QueryDataSource(org.apache.druid.query.QueryDataSource) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 25 with LookupDataSource

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

the class CalciteJoinQueryTest method testInnerJoinTwoLookupsToTableUsingNumericColumn.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinTwoLookupsToTableUsingNumericColumn(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\n" + "INNER JOIN lookup.lookyloo l1 ON l1.k = foo.m1\n" + "INNER JOIN lookup.lookyloo l2 ON l2.k = l1.k", 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\", 'DOUBLE')", ColumnType.FLOAT)).columns("k", "v0").context(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(DruidExpression.ofColumn(ColumnType.FLOAT, "m1"), DruidExpression.ofColumn(ColumnType.FLOAT, "j0.v0")), JoinType.INNER), new LookupDataSource("lookyloo"), "_j0.", equalsCondition(makeColumnExpression("j0.k"), makeColumnExpression("_j0.k")), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new CountAggregatorFactory("a0")).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L }));
}
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)

Aggregations

LookupDataSource (org.apache.druid.query.LookupDataSource)27 Test (org.junit.Test)25 Parameters (junitparams.Parameters)19 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)19 TableDataSource (org.apache.druid.query.TableDataSource)19 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)14 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)14 QueryDataSource (org.apache.druid.query.QueryDataSource)12 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)3 DataSource (org.apache.druid.query.DataSource)3 PreJoinableClause (org.apache.druid.query.planning.PreJoinableClause)3 Optional (java.util.Optional)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)2 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)2 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)2 SegmentReference (org.apache.druid.segment.SegmentReference)2 Inject (com.google.inject.Inject)1