LantaoJin commented on a change in pull request #26543: [SPARK-29911][SQL] 
Uncache cached tables when session closed
URL: https://github.com/apache/spark/pull/26543#discussion_r347697507
 
 

 ##########
 File path: 
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala
 ##########
 @@ -255,6 +255,22 @@ class ThriftServerQueryTestSuite extends 
SQLQueryTestSuite {
     }
   }
 
+  test("SPARK-29911: Uncache cached tables when session closed") {
+    val cacheManager = spark.sharedState.cacheManager
+    withJdbcStatement { statement =>
+      statement.execute("CACHE TABLE test1 AS SELECT 1")
+    }
+    // the cached data of local temporary view should be uncached
+    assert(cacheManager.isEmpty)
+    withJdbcStatement { statement =>
+      val globalTempDB = spark.sharedState.globalTempViewManager.database
+      statement.execute("CREATE GLOBAL TEMP VIEW test2 AS SELECT 1, 2")
+      statement.execute(s"CACHE TABLE $globalTempDB.test2")
+    }
+    // the cached data of global temporary view shouldn't be uncached
+    assert(!cacheManager.isEmpty)
 
 Review comment:
   OK. But it can not be cleaned in `withGlobalTempView`. So I have to do it in 
a `try..finally` block.
   ```scala
       try {
         ...
       } finally {
         withJdbcStatement { statement =>
           statement.execute(s"UNCACHE TABLE IF EXISTS 
$globalTempDB.globalTempTbl")
         }
         assert(cacheManager.isEmpty)
       }
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to