This is an automated email from the ASF dual-hosted git repository. huajianlan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 46776af2a3 [fix](Nereids)plan translator lost other conjuncts on hash join node (#12391) 46776af2a3 is described below commit 46776af2a3f6df618ac1f53c89d75309bd1f9819 Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Wed Sep 7 11:32:05 2022 +0800 [fix](Nereids)plan translator lost other conjuncts on hash join node (#12391) In the earlier PR #11812 , we split join condition into two parts: hash join conjuncts and other condition. But we forgot to translate other condition into other conjuncts in HashJoinNode of legacy planner. So we get wrong result if query has other condition on join node. Such as: SELECT * FROM lineorder INNER JOIN part ON lo_partkey = p_partkey WHERE lo_orderkey > p_size; --- .../nereids/glue/translator/PhysicalPlanTranslator.java | 13 +++++++++++++ .../main/java/org/apache/doris/planner/HashJoinNode.java | 7 +++++++ regression-test/data/nereids_syntax_p0/join.out | 6 ++++++ regression-test/suites/nereids_syntax_p0/join.groovy | 8 ++++++++ 4 files changed, 34 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java index b59cf715c2..bea235d238 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java @@ -42,6 +42,7 @@ import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.expressions.functions.AggregateFunction; +import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; import org.apache.doris.nereids.trees.plans.AggPhase; import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; @@ -425,6 +426,18 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla .peek(s -> context.createSlotDesc(outputDescriptor, s)) .map(e -> ExpressionTranslator.translate(e, context)) .collect(Collectors.toList()); + + List<Expr> otherJoinConjuncts = hashJoin.getOtherJoinCondition() + .map(ExpressionUtils::extractConjunction) + .orElseGet(Lists::newArrayList) + .stream() + // TODO add constant expr will cause be crash, currently we only handle true literal. + // remove it after Nereids could ensure no constant expr in other join condition + .filter(e -> !(e.equals(BooleanLiteral.TRUE))) + .map(e -> ExpressionTranslator.translate(e, context)) + .collect(Collectors.toList()); + + hashJoinNode.setOtherJoinConjuncts(otherJoinConjuncts); hashJoinNode.setvIntermediateTupleDescList(Lists.newArrayList(outputDescriptor)); hashJoinNode.setvOutputTupleDesc(outputDescriptor); hashJoinNode.setvSrcToOutputSMap(srcToOutput); diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java index 8ac4ea1d9d..73c9409b22 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java @@ -1249,6 +1249,13 @@ public class HashJoinNode extends PlanNode { return true; } + /** + * Used by nereids. + */ + public void setOtherJoinConjuncts(List<Expr> otherJoinConjuncts) { + this.otherJoinConjuncts = otherJoinConjuncts; + } + /** * Used by nereids. */ diff --git a/regression-test/data/nereids_syntax_p0/join.out b/regression-test/data/nereids_syntax_p0/join.out index 2285f8357e..4859959046 100644 --- a/regression-test/data/nereids_syntax_p0/join.out +++ b/regression-test/data/nereids_syntax_p0/join.out @@ -54,3 +54,9 @@ 1310179 6 1312 1455 29 19921110 3-MEDIUM 0 15 1705830 20506457 10 1535247 68233 8 19930114 FOB 29 Supplier#000000029 VVSymB3fbwaN ARGENTINA4 ARGENTINA AMERICA 11-773-203-7342 1310179 6 1312 1455 29 19921110 3-MEDIUM 0 15 1705830 20506457 10 1535247 68233 8 19930114 FOB 9 Supplier#000000009 ,gJ6K2MKveYxQT IRAN 6 IRAN MIDDLE EAST 20-338-906-3675 +-- !inner_join_with_other_condition -- +1310179 1455 1455 42 + +-- !outer_join_with_filter -- +1310179 1455 1455 42 + diff --git a/regression-test/suites/nereids_syntax_p0/join.groovy b/regression-test/suites/nereids_syntax_p0/join.groovy index ccae67bf71..5faab7d912 100644 --- a/regression-test/suites/nereids_syntax_p0/join.groovy +++ b/regression-test/suites/nereids_syntax_p0/join.groovy @@ -67,5 +67,13 @@ suite("join") { order_qt_cross_join """ SELECT * FROM lineorder CROSS JOIN supplier; """ + + order_qt_inner_join_with_other_condition """ + select lo_orderkey, lo_partkey, p_partkey, p_size from lineorder inner join part on lo_partkey = p_partkey where lo_orderkey - 1310000 > p_size; + """ + + order_qt_outer_join_with_filter """ + select lo_orderkey, lo_partkey, p_partkey, p_size from lineorder inner join part on lo_partkey = p_partkey where lo_orderkey - 1310000 > p_size; + """ } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org