Skip to content

Commit

Permalink
Fixing a case where datatype mismatch was happenning in join (#15541)
Browse files Browse the repository at this point in the history
  • Loading branch information
somu-imply committed Dec 12, 2023
1 parent 91ca8e7 commit 38f3cf9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void onMatch(RelOptRuleCall call)
if (postJoinFilter != null) {
relBuilder = relBuilder.filter(postJoinFilter);
}

relBuilder.convert(join.getRowType(), false);
call.transformTo(relBuilder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6466,4 +6466,85 @@ public void testJoinsOverUnnestOverFilterDSOverJoin()
)
);
}

@Test
public void testLeftJoinsOnTwoWithTables()
{
Map<String, Object> context = new HashMap<>(QUERY_CONTEXT_DEFAULT);
testQuery(
"with raw1 as (\n"
+ " select\n"
+ " dim1,\n"
+ " count(*)/2 as c\n"
+ " from foo\n"
+ " GROUP BY 1\n"
+ "),\n"
+ " raw2 as (\n"
+ " select \n"
+ " dim1,\n"
+ " count(*)/2 as c\n"
+ " from foo\n"
+ " GROUP BY 1\n"
+ ")\n"
+ "select\n"
+ " r1.c-r2.c\n"
+ "from raw1 r1\n"
+ "left join raw2 r2\n"
+ "on r1.dim1 = r2.dim1",
context,
ImmutableList.of(
newScanQueryBuilder()
.dataSource(
join(
new QueryDataSource(
GroupByQuery.builder()
.setInterval(querySegmentSpec(Filtration.eternity()))
.setGranularity(Granularities.ALL)
.setDataSource(new TableDataSource(CalciteTests.DATASOURCE1))
.setDimensions(new DefaultDimensionSpec("dim1", "d0", ColumnType.STRING))
.setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0")))
.setPostAggregatorSpecs(expressionPostAgg(
"p0",
"(\"a0\" / 2)",
ColumnType.LONG
))
.setContext(context)
.build()
),
new QueryDataSource(
GroupByQuery.builder()
.setInterval(querySegmentSpec(Filtration.eternity()))
.setGranularity(Granularities.ALL)
.setDataSource(new TableDataSource(CalciteTests.DATASOURCE1))
.setDimensions(new DefaultDimensionSpec("dim1", "d0", ColumnType.STRING))
.setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0")))
.setPostAggregatorSpecs(expressionPostAgg(
"p0",
"(\"a0\" / 2)",
ColumnType.LONG
))
.setContext(context)
.build()
),
"j0.",
"(\"d0\" == \"j0.d0\")",
JoinType.LEFT
)
)
.intervals(querySegmentSpec(Filtration.eternity()))
.columns("v0")
.virtualColumns(expressionVirtualColumn("v0", "(\"p0\" - \"j0.p0\")", ColumnType.LONG))
.context(context)
.build()
),
ImmutableList.of(
new Object[]{0L},
new Object[]{0L},
new Object[]{0L},
new Object[]{0L},
new Object[]{0L},
new Object[]{0L}
)
);
}
}

0 comments on commit 38f3cf9

Please sign in to comment.