[fix](planner) fix non-equal out join is not supported (#9156)
This commit is contained in:
@ -218,6 +218,7 @@ public class TableRef implements ParseNode, Writable {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public JoinOperator getJoinOp() {
|
||||
// if it's not explicitly set, we're doing an inner join
|
||||
return (joinOp == null ? JoinOperator.INNER_JOIN : joinOp);
|
||||
@ -575,7 +576,15 @@ 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) {
|
||||
Expr expr = onClause.clone();
|
||||
onClause = rewriter.rewrite(onClause, analyzer, ExprRewriter.ClauseType.ON_CLAUSE);
|
||||
if (joinOp.isOuterJoin() || joinOp.isSemiAntiJoin()) {
|
||||
if (onClause instanceof BoolLiteral && !((BoolLiteral) onClause).getValue()) {
|
||||
onClause = expr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String joinOpToSql() {
|
||||
|
||||
@ -2120,4 +2120,38 @@ public class QueryPlanTest {
|
||||
String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, sql);
|
||||
Assert.assertTrue(explainString.contains("1 | 10 | 1 | 1 | 1"));
|
||||
}
|
||||
|
||||
@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"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user