You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by tejasapatil <gi...@git.apache.org> on 2017/09/17 01:15:31 UTC

[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

GitHub user tejasapatil opened a pull request:

    https://github.com/apache/spark/pull/19257

    [SPARK-22042] [SQL] ReorderJoinPredicates can break when child's partitioning is not decided

    ## What changes were proposed in this pull request?
    
    See jira description for the bug : https://issues.apache.org/jira/browse/SPARK-22042
    
    Fix done in this PR is:  In `EnsureRequirements`, apply `ReorderJoinPredicates` over the input tree before doing its core logic. Since the tree is transformed bottom-up, we can assure that the children are resolved before doing `ReorderJoinPredicates`. 
    
    Theoretically this will guarantee to cover all such cases while keeping the code simple. My small grudge is for cosmetic reasons. This PR will look weird given that we don't call rules from other rules (not to my knowledge). I could have moved all the logic for `ReorderJoinPredicates` into `EnsureRequirements` but that will make it a but crowded. I am happy to discuss if there are better options. 
    
    ## How was this patch tested?
    
    Added a new test case

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/tejasapatil/spark SPARK-22042_ReorderJoinPredicates

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/19257.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #19257
    
----
commit 6ff4ed089777d5ec9edef8e7e53e847ec9379444
Author: Tejas Patil <te...@fb.com>
Date:   2017-09-17T01:10:31Z

    [SPARK-22042] [SQL] ReorderJoinPredicates can break when child's partitioning is not decided

----


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r156579889
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala ---
    @@ -248,13 +252,83 @@ case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {
         operator.withNewChildren(children)
       }
     
    +  /**
    +   * When the physical operators are created for JOIN, the ordering of join keys is based on order
    +   * in which the join keys appear in the user query. That might not match with the output
    +   * partitioning of the join node's children (thus leading to extra sort / shuffle being
    +   * introduced). This rule will change the ordering of the join keys to match with the
    +   * partitioning of the join nodes' children.
    +   */
    +  def reorderJoinPredicates(plan: SparkPlan): SparkPlan = {
    --- End diff --
    
    private


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/19257


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    **[Test build #81847 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81847/testReport)** for PR 19257 at commit [`6ff4ed0`](https://github.com/apache/spark/commit/6ff4ed089777d5ec9edef8e7e53e847ec9379444).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r152484490
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala ---
    @@ -265,6 +268,7 @@ case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {
               if (childPartitioning.guarantees(partitioning)) child else operator
             case _ => operator
           }
    -    case operator: SparkPlan => ensureDistributionAndOrdering(operator)
    +    case operator: SparkPlan =>
    +      ensureDistributionAndOrdering(reorderJoinPredicates.apply(operator))
    --- End diff --
    
    Could you add a comment to explain why we do it here. It is hard for new comers to understand the assumptions we made here.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84806/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Thanks! Merged to master.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    After some more thoughts, I think the best choice is to do planning bottom up. That requires a lot of refactoring and I'm fine to merge this workaround first.
    
    LGTM except one minor comment for the test.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Created https://github.com/apache/spark/pull/20041 for addressing the follow-up comments by @gatorsmile


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r153343928
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/sources/BucketedReadSuite.scala ---
    @@ -602,6 +602,28 @@ abstract class BucketedReadSuite extends QueryTest with SQLTestUtils {
         )
       }
     
    +  test("SPARK-22042 ReorderJoinPredicates can break when child's partitioning is not decided") {
    +    withTable("bucketed_table", "table1", "table2") {
    +      df.write.format("parquet").saveAsTable("table1")
    +      df.write.format("parquet").saveAsTable("table2")
    +      df.write.format("parquet").bucketBy(8, "j", "k").saveAsTable("bucketed_table")
    +
    +      withSQLConf(SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "0") {
    +        sql("""
    +              |SELECT *
    +              |FROM (
    +              |  SELECT a.i, a.j, a.k
    +              |  FROM bucketed_table a
    +              |  JOIN table1 b
    +              |  ON a.i = b.i
    +              |) c
    +              |JOIN table2
    +              |ON c.i = table2.i
    +              |""".stripMargin).explain()
    --- End diff --
    
    changed


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r153343898
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala ---
    @@ -265,6 +268,7 @@ case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {
               if (childPartitioning.guarantees(partitioning)) child else operator
             case _ => operator
           }
    -    case operator: SparkPlan => ensureDistributionAndOrdering(operator)
    +    case operator: SparkPlan =>
    +      ensureDistributionAndOrdering(reorderJoinPredicates.apply(operator))
    --- End diff --
    
    It feels like having a rule invoked in such fashion is in-consistent compared to rest of the codebase .... from point of view of someone new to codebase, it will look odd. I removed the rule and instead moved this methods inside `EnsureRequirements`. Let me know how you feel about the changed version


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    By "placeholder shuffle nodes" you mean dummy ones ? We need to know the exact partitioning of the children which dummy nodes won't give (maybe I didn't get what you meant). My fear is that `EnsureRequirements` might choose to make some decisions about shuffle which would affect the results of `ReorderJoinPredicates` rule.
    
    I agree that we need to rethink about the planning phase for adding shuffles.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by ash211 <gi...@git.apache.org>.
Github user ash211 commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    @cloud-fan @gatorsmile any more changes needed on this PR before merging?  I don't see any un-addressed comments left.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by dongjoon-hyun <gi...@git.apache.org>.
Github user dongjoon-hyun commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Gentle ping~


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r156579879
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala ---
    @@ -248,13 +252,83 @@ case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {
         operator.withNewChildren(children)
       }
     
    +  /**
    +   * When the physical operators are created for JOIN, the ordering of join keys is based on order
    +   * in which the join keys appear in the user query. That might not match with the output
    +   * partitioning of the join node's children (thus leading to extra sort / shuffle being
    +   * introduced). This rule will change the ordering of the join keys to match with the
    +   * partitioning of the join nodes' children.
    +   */
    +  def reorderJoinPredicates(plan: SparkPlan): SparkPlan = {
    +    def reorderJoinKeys(
    --- End diff --
    
    We do not prefer the embedded function.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    **[Test build #81847 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81847/testReport)** for PR 19257 at commit [`6ff4ed0`](https://github.com/apache/spark/commit/6ff4ed089777d5ec9edef8e7e53e847ec9379444).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by dongjoon-hyun <gi...@git.apache.org>.
Github user dongjoon-hyun commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Thank you for your update, @tejasapatil .
    
    @cloud-fan and @gatorsmile . Could you give us some direction?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by felixcheung <gi...@git.apache.org>.
Github user felixcheung commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    how is this coming? it will be good to fix this in 2.2?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    retest this please


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    @dongjoon-hyun : It will take me time to get back to this. Having said that , its not ideal to have master is bad state. How about disabling the rule by default (using a config) ?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r152484440
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala ---
    @@ -265,6 +268,7 @@ case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {
               if (childPartitioning.guarantees(partitioning)) child else operator
             case _ => operator
           }
    -    case operator: SparkPlan => ensureDistributionAndOrdering(operator)
    +    case operator: SparkPlan =>
    +      ensureDistributionAndOrdering(reorderJoinPredicates.apply(operator))
    --- End diff --
    
    Then, do something like 
    ```Scala
    ensureDistributionAndOrdering(ReorderJoinPredicates(operator))
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    > We need to know the exact partitioning of the children which dummy nodes won't give
    
    We only add the dummy shuffle node when it's necessary, e.g.
    ```
           hash-join
              /      \
        child1   child2
    ```
    
    Let's say `hash-join` needs children to be clustered by a, b, and `child1` is already partitioned by a, and `child2` has no partitioning. After adding the dummy nodes:
    ```
           hash-join
              /      \
             /     dummy-shuffle
            /            |
        child1    child2
    ```
    Now we still keep exact partitioning, i.e. left child is partitioned by a, right child is partitioned by a,b 


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84232/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    **[Test build #84232 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84232/testReport)** for PR 19257 at commit [`d9620ef`](https://github.com/apache/spark/commit/d9620ef9111c8167f86632c4e4c343e9d70a6375).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Or we could move forward with the current approach and defer the refactoring around how shuffles are added in planning phase.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    @felixcheung Don't worry, the bug only exists in the master branch, so it won't block the 2.2.1 release. I have corrected the JIRA ticket's affected version to 2.3 . Also I'm looking into this issue


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    **[Test build #84232 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84232/testReport)** for PR 19257 at commit [`d9620ef`](https://github.com/apache/spark/commit/d9620ef9111c8167f86632c4e4c343e9d70a6375).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    **[Test build #84806 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84806/testReport)** for PR 19257 at commit [`d9620ef`](https://github.com/apache/spark/commit/d9620ef9111c8167f86632c4e4c343e9d70a6375).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by dongjoon-hyun <gi...@git.apache.org>.
Github user dongjoon-hyun commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Thank you for the decision, @cloud-fan . It's great to see the progress on this!


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81847/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Maybe we need to rethink about the planning phase for adding shuffles. How about we add a placeholder for shuffle node and then replace the placeholder with actual shuffle node in `EnsureRequirements`? Then we can make sure the plan tree is always resolved.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r152484350
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala ---
    @@ -31,6 +32,8 @@ import org.apache.spark.sql.internal.SQLConf
      * input partition ordering requirements are met.
      */
     case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {
    +  private val reorderJoinPredicates = new ReorderJoinPredicates
    --- End diff --
    
    Change `class ReorderJoinPredicates ` to `object ReorderJoinPredicates `?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r156580049
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/sources/BucketedReadSuite.scala ---
    @@ -602,6 +602,37 @@ abstract class BucketedReadSuite extends QueryTest with SQLTestUtils {
         )
       }
     
    +  test("SPARK-22042 ReorderJoinPredicates can break when child's partitioning is not decided") {
    +    withTable("bucketed_table", "table1", "table2") {
    +      df.write.format("parquet").saveAsTable("table1")
    +      df.write.format("parquet").saveAsTable("table2")
    +      df.write.format("parquet").bucketBy(8, "j", "k").saveAsTable("bucketed_table")
    +
    +      withSQLConf(SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "0") {
    +        checkAnswer(
    +          sql("""
    +                |SELECT ab.i, ab.j, ab.k, c.i, c.j, c.k
    +                |FROM (
    +                |  SELECT a.i, a.j, a.k
    +                |  FROM bucketed_table a
    +                |  JOIN table1 b
    +                |  ON a.i = b.i
    +                |) ab
    +                |JOIN table2 c
    +                |ON ab.i = c.i
    +                |""".stripMargin),
    +          sql("""
    +                |SELECT a.i, a.j, a.k, c.i, c.j, c.k
    +                |FROM bucketed_table a
    +                |JOIN table1 b
    +                |ON a.i = b.i
    +                |JOIN table2 c
    +                |ON a.i = c.i
    +                |""".stripMargin))
    --- End diff --
    
    Please follow the other test cases


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r156579907
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala ---
    @@ -248,13 +252,83 @@ case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {
         operator.withNewChildren(children)
       }
     
    +  /**
    +   * When the physical operators are created for JOIN, the ordering of join keys is based on order
    +   * in which the join keys appear in the user query. That might not match with the output
    +   * partitioning of the join node's children (thus leading to extra sort / shuffle being
    +   * introduced). This rule will change the ordering of the join keys to match with the
    +   * partitioning of the join nodes' children.
    +   */
    +  def reorderJoinPredicates(plan: SparkPlan): SparkPlan = {
    +    def reorderJoinKeys(
    +        leftKeys: Seq[Expression],
    +        rightKeys: Seq[Expression],
    +        leftPartitioning: Partitioning,
    +        rightPartitioning: Partitioning): (Seq[Expression], Seq[Expression]) = {
    +
    +      def reorder(expectedOrderOfKeys: Seq[Expression],
    +                  currentOrderOfKeys: Seq[Expression]): (Seq[Expression], Seq[Expression]) = {
    --- End diff --
    
    indents.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Jenkins test this please


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    **[Test build #84806 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84806/testReport)** for PR 19257 at commit [`d9620ef`](https://github.com/apache/spark/commit/d9620ef9111c8167f86632c4e4c343e9d70a6375).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can bre...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19257#discussion_r151714611
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/sources/BucketedReadSuite.scala ---
    @@ -602,6 +602,28 @@ abstract class BucketedReadSuite extends QueryTest with SQLTestUtils {
         )
       }
     
    +  test("SPARK-22042 ReorderJoinPredicates can break when child's partitioning is not decided") {
    +    withTable("bucketed_table", "table1", "table2") {
    +      df.write.format("parquet").saveAsTable("table1")
    +      df.write.format("parquet").saveAsTable("table2")
    +      df.write.format("parquet").bucketBy(8, "j", "k").saveAsTable("bucketed_table")
    +
    +      withSQLConf(SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "0") {
    +        sql("""
    +              |SELECT *
    +              |FROM (
    +              |  SELECT a.i, a.j, a.k
    +              |  FROM bucketed_table a
    +              |  JOIN table1 b
    +              |  ON a.i = b.i
    +              |) c
    +              |JOIN table2
    +              |ON c.i = table2.i
    +              |""".stripMargin).explain()
    --- End diff --
    
    use checkAnswer instead of explain in the test


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by tejasapatil <gi...@git.apache.org>.
Github user tejasapatil commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    cc @cloud-fan @gatorsmile @sameeragarwal for review


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    LGTM except a few style comments. We can merge it and fix it in the follow-up PR. Thanks!


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #19257: [SPARK-22042] [SQL] ReorderJoinPredicates can break when...

Posted by dongjoon-hyun <gi...@git.apache.org>.
Github user dongjoon-hyun commented on the issue:

    https://github.com/apache/spark/pull/19257
  
    Hi, All.
    Master branch still has this problem. Can we proceed this?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org