You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/10/29 19:32:36 UTC

[GitHub] [spark] sunchao opened a new pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

sunchao opened a new pull request #30187:
URL: https://github.com/apache/spark/pull/30187


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   In `CatalogImpl.refreshTable`, this moves the `uncacheQuery` call out of the condition `if (cache.nonEmpty)` so that it will be called whether the table itself is cached or not. 
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   In the case like the following:
   ```sql
   CREATE TABLE t ...;
   CREATE VIEW t1 AS SELECT * FROM t;
   REFRESH TABLE t;
   ```
   
   If the table `t` is refreshed, the view `t1` which is depending on `t` will not be invalidated. This could lead to incorrect result and is similar to [SPARK-19765](https://issues.apache.org/jira/browse/SPARK-19765). In addition, if we have:
   
   ```sql 
   CREATE TABLE t ...;
   CACHE TABLE t;
   CREATE VIEW t1 AS SELECT * FROM t;
   REFRESH TABLE t;
   ```
   
   Then the view `t1` will be refreshed. The behavior is inconsistent.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   Yes, with the change any cache that are depending on the table refreshed will be invalidated with the change. Previously this only happens if the table itself is cached.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   
   Added a new UT for the case.


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

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



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


[GitHub] [spark] sunchao commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r517590557



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +527,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)

Review comment:
       hmm which migration guide should I add this to? note Spark already invalidate cache when the target table is cached, and this just extend it to the case when the table itself is not cached.




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

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



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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r517770443



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +527,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)

Review comment:
       Thanks @sunchao 




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

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



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


[GitHub] [spark] sunchao commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
sunchao commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719105597


   cc @cloud-fan @dongjoon-hyun @viirya 


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

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



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


[GitHub] [spark] AmplabJenkins commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719051860






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

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



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


[GitHub] [spark] viirya commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r514886343



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +524,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)
+
     if (cache.nonEmpty) {
       // save the cache name and cache level for recreation
       val cacheName = cache.get.cachedRepresentation.cacheBuilder.tableName
       val cacheLevel = cache.get.cachedRepresentation.cacheBuilder.storageLevel
 
-      // uncache the logical plan.
-      sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)
-
       // recache with the same name and cache level.
       sparkSession.sharedState.cacheManager.cacheQuery(table, cacheName, cacheLevel)

Review comment:
       Nvm, we only recache if the table is cached. So for this case, the table is not cached at all, we don't recache it.




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

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719076384


   Test FAILed.
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/130417/
   Test FAILed.


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

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



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


[GitHub] [spark] dongjoon-hyun commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719136757


   Thank you so much, @sunchao !


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

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



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


[GitHub] [spark] viirya commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r514884174



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +524,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)
+
     if (cache.nonEmpty) {
       // save the cache name and cache level for recreation
       val cacheName = cache.get.cachedRepresentation.cacheBuilder.tableName
       val cacheLevel = cache.get.cachedRepresentation.cacheBuilder.storageLevel
 
-      // uncache the logical plan.
-      sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)
-
       // recache with the same name and cache level.
       sparkSession.sharedState.cacheManager.cacheQuery(table, cacheName, cacheLevel)

Review comment:
       Hmm, we will recache the table lazily. But for other caches referencing this table, we just uncache them and don't recache them. Does it sound inconsistent?




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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-718974783


   **[Test build #130417 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/130417/testReport)** for PR 30187 at commit [`96c9263`](https://github.com/apache/spark/commit/96c926336c4bff1c78074f9bbc36ad6b733b98d2).


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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719113670


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


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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-718998299


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35021/
   


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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719043189


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35022/
   


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

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



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


[GitHub] [spark] SparkQA removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-718974783


   **[Test build #130417 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/130417/testReport)** for PR 30187 at commit [`96c9263`](https://github.com/apache/spark/commit/96c926336c4bff1c78074f9bbc36ad6b733b98d2).


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

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



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


[GitHub] [spark] gatorsmile commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
gatorsmile commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r517084348



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -504,6 +504,9 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
    * If this table is cached as an InMemoryRelation, drop the original cached version and make the
    * new version cached lazily.
    *
+   * In addition, refreshing a table also invalidate all caches that have reference to the table
+   * in a cascading manner. This is to prevent incorrect result from the otherwise staled caches.

Review comment:
       Add it to the migration guide?




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

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



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


[GitHub] [spark] AmplabJenkins commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719076377






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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719012873


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35021/
   


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

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



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


[GitHub] [spark] AmplabJenkins commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719012894






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

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719114234






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

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r514830043



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
##########
@@ -1208,4 +1208,24 @@ class CachedTableSuite extends QueryTest with SQLTestUtils
       assert(spark.sharedState.cacheManager.lookupCachedData(df).isDefined)
     }
   }
+
+  test("SPARK-33290: REFRESH TABLE should invalidate all caches referencing the table") {
+    withTable("t") {
+      withTempPath { path =>
+        withTempView("tempView1", "tempView2") {
+          Seq((1 -> "a")).toDF("i", "j").write.parquet(path.getCanonicalPath)
+          sql(s"CREATE TABLE t USING parquet LOCATION '${path.toURI}'")
+          sql("CREATE VIEW tempView1 AS SELECT * FROM t")

Review comment:
       nit: this is not temp view, maybe naming it `view1`?




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

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719012894


   Merged build finished. Test FAILed.


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

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



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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r517761235



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +527,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)

Review comment:
       I think he meant https://github.com/apache/spark/blob/master/docs/sql-migration-guide.md to update. I tend to agree that it's safe to mention it unless it's obviously a bug fix.




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

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



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


[GitHub] [spark] SparkQA removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719025581


   **[Test build #130418 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/130418/testReport)** for PR 30187 at commit [`7c33303`](https://github.com/apache/spark/commit/7c33303071e92ae5331afde0775580db5c6c2c25).


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

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719076377


   Merged build finished. Test FAILed.


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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719075927


   **[Test build #130417 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/130417/testReport)** for PR 30187 at commit [`96c9263`](https://github.com/apache/spark/commit/96c926336c4bff1c78074f9bbc36ad6b733b98d2).
    * This patch **fails Spark unit tests**.
    * This patch merges cleanly.
    * This patch adds no public classes.


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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719051843


   Kubernetes integration test status success
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35022/
   


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

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719012898


   Test FAILed.
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/35021/
   Test FAILed.


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

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



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


[GitHub] [spark] sunchao commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r517769750



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +527,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)

Review comment:
       Created #30256




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

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



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


[GitHub] [spark] sunchao commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
sunchao commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r517762296



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +527,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)

Review comment:
       Thanks for the pointer @HyukjinKwon . I'll update there.




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

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



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


[GitHub] [spark] cloud-fan commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r514830896



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
##########
@@ -1208,4 +1208,24 @@ class CachedTableSuite extends QueryTest with SQLTestUtils
       assert(spark.sharedState.cacheManager.lookupCachedData(df).isDefined)
     }
   }
+
+  test("SPARK-33290: REFRESH TABLE should invalidate all caches referencing the table") {
+    withTable("t") {
+      withTempPath { path =>
+        withTempView("tempView1", "tempView2") {
+          Seq((1 -> "a")).toDF("i", "j").write.parquet(path.getCanonicalPath)
+          sql(s"CREATE TABLE t USING parquet LOCATION '${path.toURI}'")
+          sql("CREATE VIEW tempView1 AS SELECT * FROM t")
+          sql("CACHE TABLE tempView2 AS SELECT i FROM tempView1")
+          checkAnswer(sql("SELECT * FROM tempView1"), Seq(Row(1, "a")))
+          checkAnswer(sql("SELECT * FROM tempView2"), Seq(Row(1)))
+
+          Utils.deleteRecursively(path)
+          sql("REFRESH TABLE tempView1")

Review comment:
       does it still work if we only refresh table t?




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

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



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719051860






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

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



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


[GitHub] [spark] AmplabJenkins commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719114234






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

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



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


[GitHub] [spark] gatorsmile commented on a change in pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
gatorsmile commented on a change in pull request #30187:
URL: https://github.com/apache/spark/pull/30187#discussion_r517084478



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala
##########
@@ -524,14 +527,17 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     // If this table is cached as an InMemoryRelation, drop the original
     // cached version and make the new version cached lazily.
     val cache = sparkSession.sharedState.cacheManager.lookupCachedData(table)
+
+    // uncache the logical plan.
+    // note this is a no-op for the table itself if it's not cached, but will invalidate all
+    // caches referencing this table.
+    sparkSession.sharedState.cacheManager.uncacheQuery(table, cascade = true)

Review comment:
       Add it to the migration guide?




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

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



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


[GitHub] [spark] SparkQA commented on pull request #30187: [SPARK-33290][SQL] REFRESH TABLE should invalidate cache even though the table itself may not be cached

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30187:
URL: https://github.com/apache/spark/pull/30187#issuecomment-719025581


   **[Test build #130418 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/130418/testReport)** for PR 30187 at commit [`7c33303`](https://github.com/apache/spark/commit/7c33303071e92ae5331afde0775580db5c6c2c25).


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

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



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