Search in sources :

Example 6 with LookupDataSource

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

the class CalciteJoinQueryTest method testInnerJoinSubqueryWithSelectorFilter.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinSubqueryWithSelectorFilter(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize due to 'concat' expression.
    cannotVectorize();
    testQuery("SELECT dim1, l1.k " + "FROM foo INNER JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 " + "ON foo.dim1 = l1.k and l1.k = 'abc'", queryContext, ImmutableList.of(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.", StringUtils.format("(%s && %s)", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.d0")), equalsCondition(makeExpression("'abc'"), makeColumnExpression("j0.d0"))), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "j0.d0").context(queryContext).build()), ImmutableList.of(new Object[] { "abc", "abc" }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 7 with LookupDataSource

use of org.apache.druid.query.LookupDataSource 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 8 with LookupDataSource

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

the class CalciteJoinQueryTest method testWhereInSelectNullFromLookup.

@Test
public void testWhereInSelectNullFromLookup() throws Exception {
    // Regression test for https://github.com/apache/druid/issues/9646.
    cannotVectorize();
    testQuery("SELECT * FROM foo where dim1 IN (SELECT NULL FROM lookup.lookyloo)", ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(new LookupDataSource("lookyloo")).setInterval(querySegmentSpec(Filtration.eternity())).setVirtualColumns(expressionVirtualColumn("v0", "null", ColumnType.STRING)).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.d0")), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("v0", "null", ColumnType.STRING)).columns("__time", "cnt", "dim2", "dim3", "m1", "m2", "unique_dim1", "v0").context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of());
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 9 with LookupDataSource

use of org.apache.druid.query.LookupDataSource 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 10 with LookupDataSource

use of org.apache.druid.query.LookupDataSource 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

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