GitHub user cloud-fan opened a pull request:

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

    [SPARK-20897][SQL] cached self-join should not fail

    ## What changes were proposed in this pull request?
    
    The failed test case is, we have a `SortMergeJoinExec` for a self-join, 
which means we have a `ReusedExchange` node in the query plan. It works fine 
without caching, but throws an exception in 
`SortMergeJoinExec.outputPartitioning` if we cache it.
    
    The root cause is, `ReusedExchange` doesn't propagate the output 
partitioning from its child, so in `SortMergeJoinExec.outputPartitioning` we 
create `PartitioningCollection` with a hash partitioning and an unknown 
partitioning, and fail.
    
    This bug is mostly fine, because inserting the `ReusedExchange` is the last 
step to prepare the physical plan, we won't call 
`SortMergeJoinExec.outputPartitioning` anymore after this.
    
    However, if the dataframe is cached, the physical plan of it becomes 
`InMemoryTableScanExec`, which contains another physical plan representing the 
cached query, and it has gone through the entire planning phase and may have 
`ReusedExchange`. Then the planner call 
`InMemoryTableScanExec.outputPartitioning`, which then calls 
`SortMergeJoinExec.outputPartitioning` and trigger this bug.
    
    ## How was this patch tested?
    
    a new regression test

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

    $ git pull https://github.com/cloud-fan/spark bug

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

    https://github.com/apache/spark/pull/18121.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 #18121
    
----
commit ca4a3d1c62b172376694ba2435551653de82a345
Author: Wenchen Fan <[email protected]>
Date:   2017-05-26T15:06:40Z

    cached self-join should not fail

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to