use of org.apache.druid.query.TableDataSource 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.TableDataSource 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.TableDataSource in project druid by druid-io.
the class CalciteJoinQueryTest method testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.
@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess(Map<String, Object> queryContext) throws Exception {
queryContext = withLeftDirectAccessEnabled(queryContext);
testQuery("with abc as\n" + "(\n" + " SELECT dim1, \"__time\", m1 from foo WHERE \"dim1\" = '10.1'\n" + ")\n" + "SELECT t1.dim1, t1.\"__time\" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1\n", queryContext, ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).filters(new SelectorDimFilter("dim1", "10.1", null)).columns(ImmutableList.of("dim1")).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(queryContext).build()), "j0.", equalsCondition(makeExpression("'10.1'"), makeColumnExpression("j0.dim1")), JoinType.LEFT, selector("dim1", "10.1", null))).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("v0", "\'10.1\'", ColumnType.STRING)).columns("__time", "v0").context(queryContext).build()), ImmutableList.of(new Object[] { "10.1", 946771200000L }));
}
use of org.apache.druid.query.TableDataSource in project druid by druid-io.
the class CalciteJoinQueryTest method testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.
@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess(Map<String, Object> queryContext) throws Exception {
queryContext = withLeftDirectAccessEnabled(queryContext);
testQuery("with abc as\n" + "(\n" + " SELECT dim1, \"__time\", m1 from foo WHERE \"dim1\" = '10.1'\n" + ")\n" + "SELECT t1.dim1, t1.\"__time\" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1'\n", queryContext, ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).filters(new SelectorDimFilter("dim1", "10.1", null)).columns(ImmutableList.of("dim1")).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(queryContext).build()), "j0.", equalsCondition(makeExpression("'10.1'"), makeColumnExpression("j0.dim1")), JoinType.LEFT, selector("dim1", "10.1", null))).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("v0", "\'10.1\'", ColumnType.STRING)).columns("__time", "v0").context(queryContext).build()), ImmutableList.of(new Object[] { "10.1", 946771200000L }));
}
use of org.apache.druid.query.TableDataSource 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 }));
}
Aggregations