Search in sources :

Example 36 with DataSource

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

the class CalciteJoinQueryTest method testLeftJoinRightTableCanBeEmpty.

@Test
public void testLeftJoinRightTableCanBeEmpty() throws Exception {
    // HashJoinSegmentStorageAdapter is not vectorizable
    cannotVectorize();
    final DataSource rightTable;
    if (useDefault) {
        rightTable = InlineDataSource.fromIterable(ImmutableList.of(), RowSignature.builder().add("dim2", ColumnType.STRING).add("m2", ColumnType.DOUBLE).build());
    } else {
        rightTable = new QueryDataSource(Druids.newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).filters(new SelectorDimFilter("m2", null, null)).columns("dim2").legacy(false).build());
    }
    testQuery("SELECT v1.dim2, count(1) " + "FROM (SELECT * FROM foo where m1 > 2) v1 " + "LEFT OUTER JOIN (" + "  select dim2 from (select * from foo where m2 is null)" + ") sm ON v1.dim2 = sm.dim2 " + "group by 1", ImmutableList.of(new GroupByQuery.Builder().setDataSource(JoinDataSource.create(new QueryDataSource(Druids.newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).filters(new BoundDimFilter("m1", "2", null, true, false, null, null, StringComparators.NUMERIC)).columns("dim2").legacy(false).build()), rightTable, "j0.", "(\"dim2\" == \"j0.dim2\")", JoinType.LEFT, null, ExprMacroTable.nil())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim2", "d0", ColumnType.STRING)).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), useDefault ? ImmutableList.of(new Object[] { "", 2L }, new Object[] { "a", 1L }, new Object[] { "abc", 1L }) : ImmutableList.of(new Object[] { null, 1L }, new Object[] { "", 1L }, new Object[] { "a", 1L }, new Object[] { "abc", 1L }));
}
Also used : GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DataSource(org.apache.druid.query.DataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) JoinDataSource(org.apache.druid.query.JoinDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) InlineDataSource(org.apache.druid.query.InlineDataSource) TableDataSource(org.apache.druid.query.TableDataSource) UnionDataSource(org.apache.druid.query.UnionDataSource) Test(org.junit.Test)

Aggregations

DataSource (org.apache.druid.query.DataSource)36 TableDataSource (org.apache.druid.query.TableDataSource)23 Test (org.junit.Test)18 JoinDataSource (org.apache.druid.query.JoinDataSource)17 QueryDataSource (org.apache.druid.query.QueryDataSource)16 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)14 Filtration (org.apache.druid.sql.calcite.filtration.Filtration)12 ArrayList (java.util.ArrayList)10 InlineDataSource (org.apache.druid.query.InlineDataSource)7 HashMap (java.util.HashMap)6 Optional (java.util.Optional)6 LookupDataSource (org.apache.druid.query.LookupDataSource)6 UnionDataSource (org.apache.druid.query.UnionDataSource)6 GroupByQuery (org.apache.druid.query.groupby.GroupByQuery)6 List (java.util.List)5 Nullable (javax.annotation.Nullable)5 DimFilter (org.apache.druid.query.filter.DimFilter)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)4 ISE (org.apache.druid.java.util.common.ISE)4