GitHub user ueshin opened a pull request:
https://github.com/apache/spark/pull/13638
[SPARK-15915][SQL] CacheManager should use canonicalized plan for
planToCache.
## What changes were proposed in this pull request?
`DataFrame` with plan overriding `sameResult` but not using canonicalized
plan to compare can't cacheTable.
The example is like:
```
val localRelation = Seq(1, 2, 3).toDF()
localRelation.createOrReplaceTempView("localRelation")
spark.catalog.cacheTable("localRelation")
assert(
localRelation.queryExecution.withCachedData.collect {
case i: InMemoryRelation => i
}.size == 1)
```
and this will fail as:
```
ArrayBuffer() had size 0 instead of expected size 1
```
The reason is that when do `spark.catalog.cacheTable("localRelation")`,
`CacheManager` tries to cache for the plan wrapped by `SubqueryAlias` but when
planning for the DataFrame `localRelation`, `CacheManager` tries to find cached
table for the not-wrapped plan because the plan for DataFrame `localRelation`
is not wrapped.
Some plans like `LocalRelation`, `LogicalRDD`, etc. override `sameResult`
method, but not use canonicalized plan to compare so the `CacheManager` can't
detect the plans are the same.
This pr modifies `CacheManager` to use canonicalized plan for planToCache.
## How was this patch tested?
Added a test to check if DataFrame with plan overriding sameResult but not
using canonicalized plan to compare can cacheTable.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ueshin/apache-spark issues/SPARK-15915
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/13638.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 #13638
----
commit 9eb4c2537a7453ecce8c6e15153b1d94f000d477
Author: Takuya UESHIN <[email protected]>
Date: 2016-06-13T06:05:21Z
Add a test to check if DataFrame with plan overriding sameResult but not
using canonicalized plan to compare can cacheTable.
commit 52641f4612bd2a461ef678778f34b464a97d953d
Author: Takuya UESHIN <[email protected]>
Date: 2016-06-13T06:15:25Z
Modify CacheManager to use canonicalized plan for planToCache.
----
---
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]