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" }));
}
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 }));
}
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());
}
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 }));
}
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());
}
Aggregations