You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/12/06 07:34:29 UTC

[GitHub] [doris] morrySnow commented on a diff in pull request #14784: [feature](nereids) Support `using join` syntax

morrySnow commented on code in PR #14784:
URL: https://github.com/apache/doris/pull/14784#discussion_r1040596125


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -111,19 +114,41 @@ public List<Rule> buildRules() {
                     return new LogicalFilter<>(boundPredicates, filter.child());
                 })
             ),
-            RuleType.BINDING_JOIN_SLOT.build(
-                logicalJoin().when(Plan::canBind).thenApply(ctx -> {
-                    LogicalJoin<GroupPlan, GroupPlan> join = ctx.root;
-                    List<Expression> cond = join.getOtherJoinConjuncts().stream()
-                            .map(expr -> bind(expr, join.children(), join, ctx.cascadesContext))
-                            .collect(Collectors.toList());
-                    List<Expression> hashJoinConjuncts = join.getHashJoinConjuncts().stream()
-                            .map(expr -> bind(expr, join.children(), join, ctx.cascadesContext))
-                            .collect(Collectors.toList());
-                    return new LogicalJoin<>(join.getJoinType(),
-                            hashJoinConjuncts, cond, join.left(), join.right());
-                })
-            ),
+                RuleType.BINDING_JOIN_SLOT.build(
+                        logicalJoin().when(Plan::canBind)
+                                .whenNot(j -> j.getJoinType().equals(JoinType.USING_JOIN)).thenApply(ctx -> {
+                                    LogicalJoin<GroupPlan, GroupPlan> join = ctx.root;
+                                    List<Expression> cond = join.getOtherJoinConjuncts().stream()
+                                            .map(expr -> bind(expr, join.children(), join, ctx.cascadesContext))
+                                            .collect(Collectors.toList());
+                                    List<Expression> hashJoinConjuncts = join.getHashJoinConjuncts().stream()
+                                            .map(expr -> bind(expr, join.children(), join, ctx.cascadesContext))
+                                            .collect(Collectors.toList());
+                                    return new LogicalJoin<>(join.getJoinType(),
+                                            hashJoinConjuncts, cond, join.left(), join.right());
+                                })
+                ),
+                RuleType.BINDING_USING_JOIN_SLOT.build(
+                        logicalJoin().when(j -> j.getJoinType().equals(JoinType.USING_JOIN)).thenApply(ctx -> {
+                            LogicalJoin<GroupPlan, GroupPlan> join = ctx.root;
+                            List<Expression> unboundSlots = join.getHashJoinConjuncts();
+                            List<Expression> leftSlots = unboundSlots.stream()
+                                    .map(expr -> bind(expr, Collections.singletonList(join.left()),
+                                            join, ctx.cascadesContext))
+                                    .collect(Collectors.toList());
+                            List<Expression> rightSlots = unboundSlots.stream()
+                                    .map(expr -> bind(expr, Collections.singletonList(join.right()),
+                                            join, ctx.cascadesContext))
+                                    .collect(Collectors.toList());
+                            int size = leftSlots.size();
+                            List<Expression> hashEqExpr = new ArrayList<>();
+                            for (int i = 0; i < size; i++) {
+                                hashEqExpr.add(new EqualTo(leftSlots.get(i), rightSlots.get(i)));
+                            }
+                            return new LogicalJoin(JoinType.INNER_JOIN, hashEqExpr,
+                                    join.getOtherJoinConjuncts(), join.left(), join.right());

Review Comment:
   we put all join condition into other join conjuncts when do bind



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -111,19 +114,41 @@ public List<Rule> buildRules() {
                     return new LogicalFilter<>(boundPredicates, filter.child());
                 })
             ),
-            RuleType.BINDING_JOIN_SLOT.build(
-                logicalJoin().when(Plan::canBind).thenApply(ctx -> {
-                    LogicalJoin<GroupPlan, GroupPlan> join = ctx.root;
-                    List<Expression> cond = join.getOtherJoinConjuncts().stream()
-                            .map(expr -> bind(expr, join.children(), join, ctx.cascadesContext))
-                            .collect(Collectors.toList());
-                    List<Expression> hashJoinConjuncts = join.getHashJoinConjuncts().stream()
-                            .map(expr -> bind(expr, join.children(), join, ctx.cascadesContext))
-                            .collect(Collectors.toList());
-                    return new LogicalJoin<>(join.getJoinType(),
-                            hashJoinConjuncts, cond, join.left(), join.right());
-                })
-            ),
+                RuleType.BINDING_JOIN_SLOT.build(

Review Comment:
   this file use 4 spaces as continuation indent



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org