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