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/23 04:17:29 UTC

[GitHub] [doris] Kikyou1997 opened a new pull request, #15311: [feature-wip](nereids) Implement using join

Kikyou1997 opened a new pull request, #15311:
URL: https://github.com/apache/doris/pull/15311

   # Proposed changes
   
   Issue Number: close #xxx
   
   ## Problem summary
   
   Describe your changes.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: 
       - [ ] Yes
       - [ ] No
       - [ ] I don't know
   2. Has unit tests been added:
       - [ ] Yes
       - [ ] No
       - [ ] No Need
   3. Has document been added or modified:
       - [ ] Yes
       - [ ] No
       - [ ] No Need
   4. Does it need to update dependencies:
       - [ ] Yes
       - [ ] No
   5. Are there any changes that cannot be rolled back:
       - [ ] Yes (If Yes, please explain WHY)
       - [ ] No
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
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


[GitHub] [doris] Kikyou1997 commented on a diff in pull request #15311: [feature-wip](nereids) Implement using join

Posted by GitBox <gi...@apache.org>.
Kikyou1997 commented on code in PR #15311:
URL: https://github.com/apache/doris/pull/15311#discussion_r1057177097


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/UsingJoin.java:
##########
@@ -0,0 +1,151 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.logical;
+
+import org.apache.doris.nereids.memo.GroupExpression;
+import org.apache.doris.nereids.properties.LogicalProperties;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.JoinHint;
+import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * select col1 from t1 join t2 using(col1);
+ */
+public class UsingJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends Plan>
+        extends LogicalBinary<LEFT_CHILD_TYPE, RIGHT_CHILD_TYPE> {

Review Comment:
   Using Join is actually not any type of join.



-- 
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


[GitHub] [doris] morrySnow commented on a diff in pull request #15311: [feature-wip](nereids) Implement using join

Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #15311:
URL: https://github.com/apache/doris/pull/15311#discussion_r1057142886


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -122,41 +124,60 @@ public List<Rule> buildRules() {
                     return new LogicalFilter<>(boundPredicates, filter.child());
                 })
             ),
-            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.getHint(), 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());
+                    usingJoin().thenApply(ctx -> {
+                        UsingJoin using = ctx.root;
+                        LogicalJoin lj = new LogicalJoin(using.getJoinType() == JoinType.CROSS_JOIN
+                                ? JoinType.INNER_JOIN : using.getJoinType(),
+                                using.getHashJoinConjuncts(),
+                                using.getOtherJoinConjuncts(), using.getHint(), (Plan) using.left(),
+                                (Plan) using.right());
+                        List<Expression> unboundSlots = lj.getHashJoinConjuncts();
+                        Set<String> slotNames = new HashSet<>();
+                        List<Slot> leftOutput = new ArrayList<>(lj.left().getOutput());
+                        Collections.reverse(leftOutput);

Review Comment:
   why need reverse?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -122,41 +124,60 @@ public List<Rule> buildRules() {
                     return new LogicalFilter<>(boundPredicates, filter.child());
                 })
             ),
-            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.getHint(), 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());
+                    usingJoin().thenApply(ctx -> {
+                        UsingJoin using = ctx.root;
+                        LogicalJoin lj = new LogicalJoin(using.getJoinType() == JoinType.CROSS_JOIN
+                                ? JoinType.INNER_JOIN : using.getJoinType(),
+                                using.getHashJoinConjuncts(),
+                                using.getOtherJoinConjuncts(), using.getHint(), (Plan) using.left(),
+                                (Plan) using.right());

Review Comment:
   why need to cast to `Plan`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/UsingJoin.java:
##########
@@ -0,0 +1,151 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.logical;
+
+import org.apache.doris.nereids.memo.GroupExpression;
+import org.apache.doris.nereids.properties.LogicalProperties;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.JoinHint;
+import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * select col1 from t1 join t2 using(col1);
+ */
+public class UsingJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends Plan>
+        extends LogicalBinary<LEFT_CHILD_TYPE, RIGHT_CHILD_TYPE> {

Review Comment:
   should implement `org.apache.doris.nereids.trees.plans.algebra.Join`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java:
##########
@@ -127,7 +127,6 @@ public static StatsDeriveResult estimate(StatsDeriveResult leftStats, StatsDeriv
             rowCount = estimateFullOuterJoin(leftStats, rightStats, join);
         } else {
             LOG.warn("join type is not supported: " + joinType);
-            throw new RuntimeException("joinType is not supported");

Review Comment:
   why remove this?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -122,41 +124,60 @@ public List<Rule> buildRules() {
                     return new LogicalFilter<>(boundPredicates, filter.child());
                 })
             ),
-            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.getHint(), 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());
+                    usingJoin().thenApply(ctx -> {
+                        UsingJoin using = ctx.root;
+                        LogicalJoin lj = new LogicalJoin(using.getJoinType() == JoinType.CROSS_JOIN
+                                ? JoinType.INNER_JOIN : using.getJoinType(),
+                                using.getHashJoinConjuncts(),
+                                using.getOtherJoinConjuncts(), using.getHint(), (Plan) using.left(),
+                                (Plan) using.right());
+                        List<Expression> unboundSlots = lj.getHashJoinConjuncts();
+                        Set<String> slotNames = new HashSet<>();
+                        List<Slot> leftOutput = new ArrayList<>(lj.left().getOutput());
+                        Collections.reverse(leftOutput);
+                        List<Expression> leftSlots = new ArrayList<>();
+                        Scope scope = toScope(leftOutput.stream()
+                                .filter(s -> !slotNames.contains(s.getName()))
+                                .peek(s -> slotNames.add(s.getName())).collect(
+                                        Collectors.toList()));
+                        for (Expression unboundSlot : unboundSlots) {
+                            Expression expression = new SlotBinder(scope, lj, ctx.cascadesContext).bind(unboundSlot);
+                            leftSlots.add(expression);
+                        }
+                        slotNames.clear();

Review Comment:
   What is the purpose of slotNames?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -1233,13 +1232,17 @@ private LogicalPlan withJoinRelations(LogicalPlan input, RelationContext ctx) {
                     throw new ParseException("Invalid join hint: " + hint, hintCtx);
                 }
             }).orElse(JoinHint.NONE);
-
-            last = new LogicalJoin<>(joinType, ExpressionUtils.EMPTY_CONDITION,
-                    condition.map(ExpressionUtils::extractConjunction)
-                            .orElse(ExpressionUtils.EMPTY_CONDITION),
-                    joinHint,
-                    last,
-                    plan(join.relationPrimary()));
+            if (ids != null) {
+                last = new UsingJoin(joinType, last,
+                        plan(join.relationPrimary()), Collections.emptyList(), ids, joinHint);
+            } else {
+                last = new LogicalJoin<>(joinType, ExpressionUtils.EMPTY_CONDITION,
+                        condition.map(ExpressionUtils::extractConjunction)
+                                .orElse(ExpressionUtils.EMPTY_CONDITION),
+                        joinHint,
+                        last,
+                        plan(join.relationPrimary()));
+            }

Review Comment:
   move parsing hint before parsing joinCriteria, then u could just return LogicalJoin in if statement and avoid use local var `ids`



-- 
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


[GitHub] [doris] github-actions[bot] commented on pull request #15311: [feature-wip](nereids) Implement using join

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15311:
URL: https://github.com/apache/doris/pull/15311#issuecomment-1366576030

   PR approved by anyone and no changes requested.


-- 
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


[GitHub] [doris] morrySnow commented on a diff in pull request #15311: [feature-wip](nereids) Implement using join

Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #15311:
URL: https://github.com/apache/doris/pull/15311#discussion_r1057296808


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/UsingJoin.java:
##########
@@ -0,0 +1,151 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.logical;
+
+import org.apache.doris.nereids.memo.GroupExpression;
+import org.apache.doris.nereids.properties.LogicalProperties;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.JoinHint;
+import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * select col1 from t1 join t2 using(col1);
+ */
+public class UsingJoin<LEFT_CHILD_TYPE extends Plan, RIGHT_CHILD_TYPE extends Plan>
+        extends LogicalBinary<LEFT_CHILD_TYPE, RIGHT_CHILD_TYPE> {

Review Comment:
   in the current implement, it is indeed a Join algebra expression as LogicalJoin



-- 
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


[GitHub] [doris] hello-stephen commented on pull request #15311: [feature-wip](nereids) Implement using join

Posted by GitBox <gi...@apache.org>.
hello-stephen commented on PR #15311:
URL: https://github.com/apache/doris/pull/15311#issuecomment-1363737329

   TeamCity pipeline, clickbench performance test result:
    the sum of best hot time: 35.08 seconds
    load time: 683 seconds
    storage size: 17123273149 Bytes
    https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/tmp/20221223083647_clickbench_pr_67764.html


-- 
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


[GitHub] [doris] github-actions[bot] commented on pull request #15311: [feature-wip](nereids) Implement using join

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15311:
URL: https://github.com/apache/doris/pull/15311#issuecomment-1366575994

   PR approved by at least one committer and no changes requested.


-- 
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


[GitHub] [doris] morrySnow merged pull request #15311: [feature-wip](nereids) Implement using join

Posted by GitBox <gi...@apache.org>.
morrySnow merged PR #15311:
URL: https://github.com/apache/doris/pull/15311


-- 
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