You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/07/19 03:46:03 UTC

[GitHub] [flink] swuferhong opened a new pull request, #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

swuferhong opened a new pull request, #20303:
URL: https://github.com/apache/flink/pull/20303

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   For some join cases, like `SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c LEFT OUTER JOIN (SELECT * FROM T3) ON a = e`, tables `T1`, `T2` and `T3` can be translated to a multi join set because of changing their order can get the same join results. However, now, flink use calcite's default `JOIN_TO_MULTI_JOIN`  rule, this rule will not put any outer join in the same multi join set.
   
   So, this pr is aims to add `FlinkJoinToMultiJoinRule` to support translating left/outer join to one multi join set while they meet correct conditions.
   
   
   ## Brief change log
   
   - Adding new rule  `FlinkJoinToMultiJoinRule`. 
   - Adding more test cases in `FlinkJoinToMultiJoinRuleTest` to verify left/right outer join.
   
   
   ## Verifying this change
   
   - Adding more test cases in `FlinkJoinToMultiJoinRuleTest`.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? no docs.
   


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] godfreyhe commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r939529014


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRuleTest.scala:
##########
@@ -50,19 +50,214 @@ class FlinkJoinToMultiJoinRuleTest extends TableTestBase {
   }
 
   @Test
-  def testDoesNotMatchSemiJoin(): Unit = {
+  def testInnerJoinInnerJoin(): Unit = {
+    // Can translate join to multi join.
+    val sqlQuery = "SELECT * FROM T1, T2, T3 WHERE a = c AND a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testInnerJoinLeftOuterJoin(): Unit = {
+    val sqlQuery = "SELECT * FROM T1 JOIN T2 ON a =c LEFT OUTER JOIN T3 ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testInnerJoinRightOuterJoin(): Unit = {
+    // Cannot translate to one multi join set because right outer join left will generate null.
+    val sqlQuery = "SELECT * FROM T1 JOIN T2 ON a =c RIGHT OUTER JOIN T3 ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinLeftOuterJoin(): Unit = {
+    // Can translate join to multi join.
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c LEFT OUTER JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinRightOuterJoin(): Unit = {
+    // Cannot translate join to multi join.
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c RIGHT OUTER JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinInnerJoin(): Unit = {
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testRightOuterJoinRightOuterJoin(): Unit = {

Review Comment:
   please add another case (and IT case) which could reorder for all right outer joins, such as:
   SELECT * FROM T3 RIGHT OUTER JOIN (SELECT * FROM T1 RIGHT OUTER JOIN T2 ON a = c) ON c = e
   
   This case can not reorder, because the second join condition is from generate-null side



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] godfreyhe commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r934425287


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRule.java:
##########
@@ -0,0 +1,552 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.rules.CoreRules;
+import org.apache.calcite.rel.rules.FilterMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.MultiJoin;
+import org.apache.calcite.rel.rules.ProjectMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.TransformationRule;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Pair;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Flink Planner rule to flatten a tree of {@link LogicalJoin}s into a single {@link MultiJoin} with
+ * N inputs.
+ *
+ * <p>An input is not flattened if the input is a null generating input in an outer join, i.e.,
+ * either input in a full outer join, the right hand side of a left outer join, or the left hand
+ * side of a right outer join.
+ *
+ * <p>Join conditions are also pulled up from the inputs into the topmost {@link MultiJoin}, unless
+ * the input corresponds to a null generating input in an outer join,
+ *
+ * <p>Outer join information is also stored in the {@link MultiJoin}. A boolean flag indicates if
+ * the join is a full outer join, and in the case of left and right outer joins, the join type and
+ * outer join conditions are stored in arrays in the {@link MultiJoin}. This outer join information
+ * is associated with the null generating input in the outer join. So, in the case of a left outer
+ * join between A and B, the information is associated with B, not A.
+ *
+ * <p>Here are examples of the {@link MultiJoin}s constructed after this rule has been applied on
+ * following join trees.
+ *
+ * <ul>
+ *   <li>A JOIN B &rarr; MJ(A, B)
+ *   <li>A JOIN B JOIN C &rarr; MJ(A, B, C)
+ *   <li>A LEFT JOIN B &rarr; MJ(A, B), left outer join on input#1
+ *   <li>A RIGHT JOIN B &rarr; MJ(A, B), right outer join on input#0
+ *   <li>A FULL JOIN B &rarr; MJ[full](A, B)
+ *   <li>A LEFT JOIN (B JOIN C) &rarr; MJ(A, MJ(B, C))), left outer join on input#1 in the outermost
+ *       MultiJoin
+ *   <li>(A JOIN B) LEFT JOIN C &rarr; MJ(A, B, C), left outer join on input#2
+ *   <li>(A LEFT JOIN B) JOIN C &rarr; MJ(MJ(A, B), C), left outer join on input#1 of the inner
+ *       MultiJoin TODO
+ *   <li>A LEFT JOIN (B FULL JOIN C) &rarr; MJ(A, MJ[full](B, C)), left outer join on input#1 in the
+ *       outermost MultiJoin
+ *   <li>(A LEFT JOIN B) FULL JOIN (C RIGHT JOIN D) &rarr; MJ[full](MJ(A, B), MJ(C, D)), left outer
+ *       join on input #1 in the first inner MultiJoin and right outer join on input#0 in the second
+ *       inner MultiJoin
+ * </ul>
+ *
+ * <p>The constructor is parameterized to allow any sub-class of {@link Join}, not just {@link
+ * LogicalJoin}.
+ *
+ * @see FilterMultiJoinMergeRule
+ * @see ProjectMultiJoinMergeRule
+ * @see CoreRules#JOIN_TO_MULTI_JOIN
+ */
+public class FlinkJoinToMultiJoinRule extends RelRule<FlinkJoinToMultiJoinRule.Config>

Review Comment:
   add some comments about the relation between FlinkJoinToMultiJoinRule and JoinToMultiJoinRule, and which part is changed



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r936678209


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRule.java:
##########
@@ -0,0 +1,552 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.rules.CoreRules;
+import org.apache.calcite.rel.rules.FilterMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.MultiJoin;
+import org.apache.calcite.rel.rules.ProjectMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.TransformationRule;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Pair;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Flink Planner rule to flatten a tree of {@link LogicalJoin}s into a single {@link MultiJoin} with
+ * N inputs.
+ *
+ * <p>An input is not flattened if the input is a null generating input in an outer join, i.e.,
+ * either input in a full outer join, the right hand side of a left outer join, or the left hand
+ * side of a right outer join.
+ *
+ * <p>Join conditions are also pulled up from the inputs into the topmost {@link MultiJoin}, unless
+ * the input corresponds to a null generating input in an outer join,
+ *
+ * <p>Outer join information is also stored in the {@link MultiJoin}. A boolean flag indicates if
+ * the join is a full outer join, and in the case of left and right outer joins, the join type and
+ * outer join conditions are stored in arrays in the {@link MultiJoin}. This outer join information
+ * is associated with the null generating input in the outer join. So, in the case of a left outer
+ * join between A and B, the information is associated with B, not A.
+ *
+ * <p>Here are examples of the {@link MultiJoin}s constructed after this rule has been applied on
+ * following join trees.
+ *
+ * <ul>
+ *   <li>A JOIN B &rarr; MJ(A, B)
+ *   <li>A JOIN B JOIN C &rarr; MJ(A, B, C)
+ *   <li>A LEFT JOIN B &rarr; MJ(A, B), left outer join on input#1
+ *   <li>A RIGHT JOIN B &rarr; MJ(A, B), right outer join on input#0
+ *   <li>A FULL JOIN B &rarr; MJ[full](A, B)
+ *   <li>A LEFT JOIN (B JOIN C) &rarr; MJ(A, MJ(B, C))), left outer join on input#1 in the outermost
+ *       MultiJoin
+ *   <li>(A JOIN B) LEFT JOIN C &rarr; MJ(A, B, C), left outer join on input#2
+ *   <li>(A LEFT JOIN B) JOIN C &rarr; MJ(MJ(A, B), C), left outer join on input#1 of the inner

Review Comment:
   > This line can be updated
   
   done!



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r936487401


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRule.java:
##########
@@ -0,0 +1,552 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.rules.CoreRules;
+import org.apache.calcite.rel.rules.FilterMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.MultiJoin;
+import org.apache.calcite.rel.rules.ProjectMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.TransformationRule;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Pair;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Flink Planner rule to flatten a tree of {@link LogicalJoin}s into a single {@link MultiJoin} with
+ * N inputs.
+ *
+ * <p>An input is not flattened if the input is a null generating input in an outer join, i.e.,
+ * either input in a full outer join, the right hand side of a left outer join, or the left hand
+ * side of a right outer join.
+ *
+ * <p>Join conditions are also pulled up from the inputs into the topmost {@link MultiJoin}, unless
+ * the input corresponds to a null generating input in an outer join,
+ *
+ * <p>Outer join information is also stored in the {@link MultiJoin}. A boolean flag indicates if
+ * the join is a full outer join, and in the case of left and right outer joins, the join type and
+ * outer join conditions are stored in arrays in the {@link MultiJoin}. This outer join information
+ * is associated with the null generating input in the outer join. So, in the case of a left outer
+ * join between A and B, the information is associated with B, not A.
+ *
+ * <p>Here are examples of the {@link MultiJoin}s constructed after this rule has been applied on
+ * following join trees.
+ *
+ * <ul>
+ *   <li>A JOIN B &rarr; MJ(A, B)
+ *   <li>A JOIN B JOIN C &rarr; MJ(A, B, C)
+ *   <li>A LEFT JOIN B &rarr; MJ(A, B), left outer join on input#1
+ *   <li>A RIGHT JOIN B &rarr; MJ(A, B), right outer join on input#0
+ *   <li>A FULL JOIN B &rarr; MJ[full](A, B)
+ *   <li>A LEFT JOIN (B JOIN C) &rarr; MJ(A, MJ(B, C))), left outer join on input#1 in the outermost
+ *       MultiJoin
+ *   <li>(A JOIN B) LEFT JOIN C &rarr; MJ(A, B, C), left outer join on input#2
+ *   <li>(A LEFT JOIN B) JOIN C &rarr; MJ(MJ(A, B), C), left outer join on input#1 of the inner
+ *       MultiJoin TODO
+ *   <li>A LEFT JOIN (B FULL JOIN C) &rarr; MJ(A, MJ[full](B, C)), left outer join on input#1 in the
+ *       outermost MultiJoin
+ *   <li>(A LEFT JOIN B) FULL JOIN (C RIGHT JOIN D) &rarr; MJ[full](MJ(A, B), MJ(C, D)), left outer
+ *       join on input #1 in the first inner MultiJoin and right outer join on input#0 in the second
+ *       inner MultiJoin
+ * </ul>
+ *
+ * <p>The constructor is parameterized to allow any sub-class of {@link Join}, not just {@link
+ * LogicalJoin}.
+ *
+ * @see FilterMultiJoinMergeRule
+ * @see ProjectMultiJoinMergeRule
+ * @see CoreRules#JOIN_TO_MULTI_JOIN
+ */
+public class FlinkJoinToMultiJoinRule extends RelRule<FlinkJoinToMultiJoinRule.Config>

Review Comment:
   > add some comments about the relation between FlinkJoinToMultiJoinRule and JoinToMultiJoinRule, and which part is changed
   
   done!



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] godfreyhe commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r939906925


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/batch/sql/join/JoinITCase.scala:
##########
@@ -770,6 +773,214 @@ class JoinITCase(expectedJoinType: JoinType) extends BatchTestBase {
     )
   }
 
+  @Test
+  def testLeftOuterJoinReorder(): Unit = {
+    // This test is used to test the result after join to multi join and join reorder.
+    tEnv.getConfig.set(
+      OptimizerConfigOptions.TABLE_OPTIMIZER_JOIN_REORDER_ENABLED,
+      Boolean.box(true))
+    // Register table with stats to support join reorder,
+    // join order LJ(LJ(LJ(T5, T3), T2), T1) will reorder to RJ(T1, LJ(T2, LJ(T5, T3)))
+    registerCollection(

Review Comment:
   could you use ddl to create test tables ? such as: create table xxx, and Catalog#alterTableStatistics ?



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r937292379


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/MultiJoinOptimizeTest.scala:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical
+
+import org.apache.flink.table.catalog.ObjectPath
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics
+import org.apache.flink.table.planner.plan.optimize.program._
+import org.apache.flink.table.planner.utils.{TableConfigUtils, TableTestBase}
+
+import org.apache.calcite.plan.hep.HepMatchOrder
+import org.apache.calcite.rel.rules.CoreRules
+import org.apache.calcite.tools.RuleSets
+import org.junit.{Before, Test}
+
+/**
+ * Plan tests for join order using rule [[org.apache.calcite.rel.rules.LoptOptimizeJoinRule]] after
+ * joins converts to multi join set by
+ * [[org.apache.flink.table.planner.plan.rules.logical.FlinkJoinToMultiJoinRule]].
+ */
+class MultiJoinOptimizeTest extends TableTestBase {

Review Comment:
   > If we want to test join reorder, please add test cases into JoinReorderTestBase
   
   done!



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] godfreyhe commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r934425287


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRule.java:
##########
@@ -0,0 +1,552 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.rules.CoreRules;
+import org.apache.calcite.rel.rules.FilterMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.MultiJoin;
+import org.apache.calcite.rel.rules.ProjectMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.TransformationRule;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Pair;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Flink Planner rule to flatten a tree of {@link LogicalJoin}s into a single {@link MultiJoin} with
+ * N inputs.
+ *
+ * <p>An input is not flattened if the input is a null generating input in an outer join, i.e.,
+ * either input in a full outer join, the right hand side of a left outer join, or the left hand
+ * side of a right outer join.
+ *
+ * <p>Join conditions are also pulled up from the inputs into the topmost {@link MultiJoin}, unless
+ * the input corresponds to a null generating input in an outer join,
+ *
+ * <p>Outer join information is also stored in the {@link MultiJoin}. A boolean flag indicates if
+ * the join is a full outer join, and in the case of left and right outer joins, the join type and
+ * outer join conditions are stored in arrays in the {@link MultiJoin}. This outer join information
+ * is associated with the null generating input in the outer join. So, in the case of a left outer
+ * join between A and B, the information is associated with B, not A.
+ *
+ * <p>Here are examples of the {@link MultiJoin}s constructed after this rule has been applied on
+ * following join trees.
+ *
+ * <ul>
+ *   <li>A JOIN B &rarr; MJ(A, B)
+ *   <li>A JOIN B JOIN C &rarr; MJ(A, B, C)
+ *   <li>A LEFT JOIN B &rarr; MJ(A, B), left outer join on input#1
+ *   <li>A RIGHT JOIN B &rarr; MJ(A, B), right outer join on input#0
+ *   <li>A FULL JOIN B &rarr; MJ[full](A, B)
+ *   <li>A LEFT JOIN (B JOIN C) &rarr; MJ(A, MJ(B, C))), left outer join on input#1 in the outermost
+ *       MultiJoin
+ *   <li>(A JOIN B) LEFT JOIN C &rarr; MJ(A, B, C), left outer join on input#2
+ *   <li>(A LEFT JOIN B) JOIN C &rarr; MJ(MJ(A, B), C), left outer join on input#1 of the inner
+ *       MultiJoin TODO
+ *   <li>A LEFT JOIN (B FULL JOIN C) &rarr; MJ(A, MJ[full](B, C)), left outer join on input#1 in the
+ *       outermost MultiJoin
+ *   <li>(A LEFT JOIN B) FULL JOIN (C RIGHT JOIN D) &rarr; MJ[full](MJ(A, B), MJ(C, D)), left outer
+ *       join on input #1 in the first inner MultiJoin and right outer join on input#0 in the second
+ *       inner MultiJoin
+ * </ul>
+ *
+ * <p>The constructor is parameterized to allow any sub-class of {@link Join}, not just {@link
+ * LogicalJoin}.
+ *
+ * @see FilterMultiJoinMergeRule
+ * @see ProjectMultiJoinMergeRule
+ * @see CoreRules#JOIN_TO_MULTI_JOIN
+ */
+public class FlinkJoinToMultiJoinRule extends RelRule<FlinkJoinToMultiJoinRule.Config>

Review Comment:
   add some comments about the relation between FlinkJoinToMultiJoinRule and JoinToMultiJoinRule



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRuleTest.scala:
##########
@@ -49,6 +49,36 @@ class FlinkJoinToMultiJoinRuleTest extends TableTestBase {
     util.addTableSource[(Int, Long)]("T3", 'e, 'f)
   }
 
+  @Test

Review Comment:
   please add more complex tests:, such as (J means Join, LJ means LeftJoin, RJ means RightJoin)
   1. A J B LJ C J D LJ E
   2. A J B RJ C J D RJ E
   3. A RJ B RJ C
   4. A RJ B J C
   5. A FJ B J C
   6. A FJ B LJ C
   7. A FJ B RJ C
   8. A LJ B J C
   9. ...



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/MultiJoinOptimizeTest.scala:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical
+
+import org.apache.flink.table.catalog.ObjectPath
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics
+import org.apache.flink.table.planner.plan.optimize.program._
+import org.apache.flink.table.planner.utils.{TableConfigUtils, TableTestBase}
+
+import org.apache.calcite.plan.hep.HepMatchOrder
+import org.apache.calcite.rel.rules.CoreRules
+import org.apache.calcite.tools.RuleSets
+import org.junit.{Before, Test}
+
+/**
+ * Plan tests for join order using rule [[org.apache.calcite.rel.rules.LoptOptimizeJoinRule]] after
+ * joins converts to multi join set by
+ * [[org.apache.flink.table.planner.plan.rules.logical.FlinkJoinToMultiJoinRule]].
+ */
+class MultiJoinOptimizeTest extends TableTestBase {

Review Comment:
   If we want to test join reorder, please add test cases into JoinReorderTestBase



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRule.java:
##########
@@ -0,0 +1,552 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.rules.CoreRules;
+import org.apache.calcite.rel.rules.FilterMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.MultiJoin;
+import org.apache.calcite.rel.rules.ProjectMultiJoinMergeRule;
+import org.apache.calcite.rel.rules.TransformationRule;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.rex.RexVisitorImpl;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.calcite.util.Pair;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Flink Planner rule to flatten a tree of {@link LogicalJoin}s into a single {@link MultiJoin} with
+ * N inputs.
+ *
+ * <p>An input is not flattened if the input is a null generating input in an outer join, i.e.,
+ * either input in a full outer join, the right hand side of a left outer join, or the left hand
+ * side of a right outer join.
+ *
+ * <p>Join conditions are also pulled up from the inputs into the topmost {@link MultiJoin}, unless
+ * the input corresponds to a null generating input in an outer join,
+ *
+ * <p>Outer join information is also stored in the {@link MultiJoin}. A boolean flag indicates if
+ * the join is a full outer join, and in the case of left and right outer joins, the join type and
+ * outer join conditions are stored in arrays in the {@link MultiJoin}. This outer join information
+ * is associated with the null generating input in the outer join. So, in the case of a left outer
+ * join between A and B, the information is associated with B, not A.
+ *
+ * <p>Here are examples of the {@link MultiJoin}s constructed after this rule has been applied on
+ * following join trees.
+ *
+ * <ul>
+ *   <li>A JOIN B &rarr; MJ(A, B)
+ *   <li>A JOIN B JOIN C &rarr; MJ(A, B, C)
+ *   <li>A LEFT JOIN B &rarr; MJ(A, B), left outer join on input#1
+ *   <li>A RIGHT JOIN B &rarr; MJ(A, B), right outer join on input#0
+ *   <li>A FULL JOIN B &rarr; MJ[full](A, B)
+ *   <li>A LEFT JOIN (B JOIN C) &rarr; MJ(A, MJ(B, C))), left outer join on input#1 in the outermost
+ *       MultiJoin
+ *   <li>(A JOIN B) LEFT JOIN C &rarr; MJ(A, B, C), left outer join on input#2
+ *   <li>(A LEFT JOIN B) JOIN C &rarr; MJ(MJ(A, B), C), left outer join on input#1 of the inner

Review Comment:
   This line can be updated



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on PR #20303:
URL: https://github.com/apache/flink/pull/20303#issuecomment-1207416419

   @flinkbot run azure


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] flinkbot commented on pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #20303:
URL: https://github.com/apache/flink/pull/20303#issuecomment-1188565617

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "15dfbaf1a0ab15dd8ff38b6b4660b46bbc2d48e7",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "15dfbaf1a0ab15dd8ff38b6b4660b46bbc2d48e7",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 15dfbaf1a0ab15dd8ff38b6b4660b46bbc2d48e7 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r936495471


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRuleTest.scala:
##########
@@ -49,6 +49,36 @@ class FlinkJoinToMultiJoinRuleTest extends TableTestBase {
     util.addTableSource[(Int, Long)]("T3", 'e, 'f)
   }
 
+  @Test

Review Comment:
   done!



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] godfreyhe commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r939529014


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRuleTest.scala:
##########
@@ -50,19 +50,214 @@ class FlinkJoinToMultiJoinRuleTest extends TableTestBase {
   }
 
   @Test
-  def testDoesNotMatchSemiJoin(): Unit = {
+  def testInnerJoinInnerJoin(): Unit = {
+    // Can translate join to multi join.
+    val sqlQuery = "SELECT * FROM T1, T2, T3 WHERE a = c AND a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testInnerJoinLeftOuterJoin(): Unit = {
+    val sqlQuery = "SELECT * FROM T1 JOIN T2 ON a =c LEFT OUTER JOIN T3 ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testInnerJoinRightOuterJoin(): Unit = {
+    // Cannot translate to one multi join set because right outer join left will generate null.
+    val sqlQuery = "SELECT * FROM T1 JOIN T2 ON a =c RIGHT OUTER JOIN T3 ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinLeftOuterJoin(): Unit = {
+    // Can translate join to multi join.
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c LEFT OUTER JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinRightOuterJoin(): Unit = {
+    // Cannot translate join to multi join.
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c RIGHT OUTER JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinInnerJoin(): Unit = {
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testRightOuterJoinRightOuterJoin(): Unit = {

Review Comment:
   please add another case which could reorder for all right outer joins, such as:
   SELECT * FROM T3 RIGHT OUTER JOIN (SELECT * FROM T1 RIGHT OUTER JOIN T2 ON a = c) ON c = e
   
   This case can not reorder, because the second join condition is from generate-null side



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] godfreyhe closed pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
godfreyhe closed pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join
URL: https://github.com/apache/flink/pull/20303


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on PR #20303:
URL: https://github.com/apache/flink/pull/20303#issuecomment-1191090191

   @flinkbot run azure


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r939601228


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/FlinkJoinToMultiJoinRuleTest.scala:
##########
@@ -50,19 +50,214 @@ class FlinkJoinToMultiJoinRuleTest extends TableTestBase {
   }
 
   @Test
-  def testDoesNotMatchSemiJoin(): Unit = {
+  def testInnerJoinInnerJoin(): Unit = {
+    // Can translate join to multi join.
+    val sqlQuery = "SELECT * FROM T1, T2, T3 WHERE a = c AND a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testInnerJoinLeftOuterJoin(): Unit = {
+    val sqlQuery = "SELECT * FROM T1 JOIN T2 ON a =c LEFT OUTER JOIN T3 ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testInnerJoinRightOuterJoin(): Unit = {
+    // Cannot translate to one multi join set because right outer join left will generate null.
+    val sqlQuery = "SELECT * FROM T1 JOIN T2 ON a =c RIGHT OUTER JOIN T3 ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinLeftOuterJoin(): Unit = {
+    // Can translate join to multi join.
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c LEFT OUTER JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinRightOuterJoin(): Unit = {
+    // Cannot translate join to multi join.
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c RIGHT OUTER JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testLeftOuterJoinInnerJoin(): Unit = {
+    val sqlQuery =
+      "SELECT * FROM T1 LEFT OUTER JOIN T2 ON a = c JOIN (SELECT * FROM T3) ON a = e"
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testRightOuterJoinRightOuterJoin(): Unit = {

Review Comment:
   > please add another case (and IT case) which could reorder for all right outer joins, such as: SELECT * FROM T3 RIGHT OUTER JOIN (SELECT * FROM T1 RIGHT OUTER JOIN T2 ON a = c) ON c = e
   > 
   > This case can not reorder, because the second join condition is from generate-null side
   
   done!



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] swuferhong commented on pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
swuferhong commented on PR #20303:
URL: https://github.com/apache/flink/pull/20303#issuecomment-1207530512

   @flinkbot run azure


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] godfreyhe commented on a diff in pull request #20303: [FLINK-28599][table-planner] Adding FlinkJoinToMultiJoinRule to support translating left/right outer join to multi join

Posted by GitBox <gi...@apache.org>.
godfreyhe commented on code in PR #20303:
URL: https://github.com/apache/flink/pull/20303#discussion_r940018544


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/batch/sql/join/JoinITCase.scala:
##########
@@ -770,6 +773,214 @@ class JoinITCase(expectedJoinType: JoinType) extends BatchTestBase {
     )
   }
 
+  @Test
+  def testLeftOuterJoinReorder(): Unit = {
+    // This test is used to test the result after join to multi join and join reorder.
+    tEnv.getConfig.set(
+      OptimizerConfigOptions.TABLE_OPTIMIZER_JOIN_REORDER_ENABLED,
+      Boolean.box(true))
+    // Register table with stats to support join reorder,
+    // join order LJ(LJ(LJ(T5, T3), T2), T1) will reorder to RJ(T1, LJ(T2, LJ(T5, T3)))
+    registerCollection(

Review Comment:
   I create a JIRA to trace this improvements: https://issues.apache.org/jira/browse/FLINK-28866



-- 
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: issues-unsubscribe@flink.apache.org

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