William1104 commented on a change in pull request #24221: [SPARK-27248][SQL] 
`refreshTable` should recreate cache with same cache name and storage level
URL: https://github.com/apache/spark/pull/24221#discussion_r286025716
 
 

 ##########
 File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala
 ##########
 @@ -361,4 +350,81 @@ class CachedTableSuite extends QueryTest with 
SQLTestUtils with TestHiveSingleto
       
assert(spark.sharedState.cacheManager.lookupCachedData(samePlan).isDefined)
     }
   }
+
+  test("SPARK-27248 refreshTable should recreate cache with same cache name 
and storage level") {
+    // This section tests when a table is cached with its qualified name but 
its is refreshed with
+    // its unqualified name.
+    withTempDatabase { db =>
+      withTable(s"$db.cachedTable") {
+        withCache(s"$db.cachedTable") {
+          // Create table 'cachedTable' in default db for testing purpose.
+          sql(s"CREATE TABLE $db.cachedTable AS SELECT 1 AS key")
+
+          // Cache the table 'cachedTable' in temp db with qualified table 
name,
+          // and then check whether the table is cached with expected name
+          sql(s"CACHE TABLE $db.cachedTable")
+          assertCached(sql(s"select * from $db.cachedTable"), 
s"`$db`.`cachedTable`")
+          assert(spark.catalog.isCached(s"$db.cachedTable"),
+            s"Table '$db.cachedTable' should be cached.")
+
+          // Refresh the table 'cachedTable' in temp db with qualified table 
name, and then check
+          // whether the table is still cached with the same name and storage 
level.
+          sql(s"REFRESH TABLE $db.cachedTable")
+          assertCached(sql(s"select * from $db.cachedTable"), 
s"`$db`.`cachedTable`")
+          assert(spark.catalog.isCached(s"$db.cachedTable"),
+            s"Table '$db.cachedTable' should be cached after refreshing with 
its qualified name.")
+
+          // Change the active database to the temp db and refresh the table 
with unqualified
+          // table name, and then check whether the table is still cached with 
the same name and
+          // storage level.
+          // Without bug fix 'SPARK-27248', the recreated cache name will be 
changed to
+          // 'cachedTable', instead of '$db.cachedTable'
+          activateDatabase(db) {
+            sql("REFRESH TABLE cachedTable")
+            assertCached(sql("select * from cachedTable"), 
s"`$db`.`cachedTable`")
+            assert(spark.catalog.isCached("cachedTable"),
+              s"Table '$db.cachedTable' should be cached after refreshing with 
its " +
+                "unqualified name.")
+          }
+        }
+      }
+    }
+
+
+    // This section tests when a table is cached with its unqualified name but 
it is refreshed
+    // with its qualified name.
+    withTempDatabase { db =>
+      withTable("cachedTable") {
+        withCache("cachedTable") {
+          // Create table 'cachedTable' in default db for testing purpose.
+          sql("CREATE TABLE cachedTable AS SELECT 1 AS key")
+
+          // Cache the table 'cachedTable' in default db without qualified 
table name , and then
+          // check whether the table is cached with expected name.
+          sql("CACHE TABLE cachedTable")
+          assertCached(sql("select * from cachedTable"), "`cachedTable`")
 
 Review comment:
   Will update 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:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to