[Fix bug] fix non-equal out join is not supported (#8857)

This commit is contained in:
shee
2022-04-20 21:44:20 -07:00
committed by GitHub
parent 7af684ad0f
commit 2c2e06a5fe
2 changed files with 51 additions and 1 deletions

View File

@ -218,6 +218,14 @@ public class TableRef implements ParseNode, Writable {
return null;
}
public boolean isOuterJoin() {
if (joinOp != null) {
return joinOp == JoinOperator.LEFT_OUTER_JOIN || joinOp == JoinOperator.RIGHT_OUTER_JOIN
|| joinOp == JoinOperator.FULL_OUTER_JOIN;
}
return false;
}
public JoinOperator getJoinOp() {
// if it's not explicitly set, we're doing an inner join
return (joinOp == null ? JoinOperator.INNER_JOIN : joinOp);
@ -575,7 +583,12 @@ public class TableRef implements ParseNode, Writable {
public void rewriteExprs(ExprRewriter rewriter, Analyzer analyzer)
throws AnalysisException {
Preconditions.checkState(isAnalyzed);
if (onClause != null) onClause = rewriter.rewrite(onClause, analyzer, ExprRewriter.ClauseType.ON_CLAUSE);
if (onClause != null) {
if (isOuterJoin()) {
return;
}
onClause = rewriter.rewrite(onClause, analyzer, ExprRewriter.ClauseType.ON_CLAUSE);
}
}
private String joinOpToSql() {

View File

@ -2119,4 +2119,41 @@ public class QueryPlanTest {
String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, sql);
Assert.assertTrue(explainString.contains("1 | 10 | 1 | 1 | 1"));
}
/**
* for issue #8856
*/
@Test
public void testOutJoinWithOnFalse() throws Exception {
connectContext.setDatabase("default_cluster:test");
createTable("create table out_join_1\n" +
"(\n" +
" k1 int,\n" +
" v int\n" +
")\n" +
"DISTRIBUTED BY HASH(k1) BUCKETS 10\n" +
"PROPERTIES(\"replication_num\" = \"1\");");
createTable("create table out_join_2\n" +
"(\n" +
" k1 int,\n" +
" v int\n" +
")\n" +
"DISTRIBUTED BY HASH(k1) BUCKETS 10\n" +
"PROPERTIES(\"replication_num\" = \"1\");");
String sql = "explain select * from out_join_1 left join out_join_2 on out_join_1.k1 = out_join_2.k1 and 1=2;";
String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, sql);
Assert.assertFalse(explainString.contains("non-equal LEFT OUTER JOIN is not supported"));
sql = "explain select * from out_join_1 right join out_join_2 on out_join_1.k1 = out_join_2.k1 and 1=2;";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, sql);
Assert.assertFalse(explainString.contains("non-equal RIGHT OUTER JOIN is not supported"));
sql = "explain select * from out_join_1 full join out_join_2 on out_join_1.k1 = out_join_2.k1 and 1=2;";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, sql);
Assert.assertFalse(explainString.contains("non-equal FULL OUTER JOIN is not supported"));
}
}