turboFei commented on a change in pull request #31431:
URL: https://github.com/apache/spark/pull/31431#discussion_r568504039



##########
File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
##########
@@ -2581,6 +2581,48 @@ abstract class SQLQuerySuiteBase extends QueryTest with 
SQLTestUtils with TestHi
       }
     }
   }
+
+  test("SPARK-34322: When refreshing a view, also refresh its underlying 
tables") {
+    withTempDir { dir1 =>
+      withTempDir { dir2 =>
+        withTable("ta", "tb") {
+          withView("v") {
+            withTempView("tv1", "tv2") {
+              sql(s"create table ta(id int) using parquet")
+              sql(s"create table tb(id int) using parquet")
+              sql("create view v as select * from ta")
+              sql("create temporary view tv1 as select * from tb")
+              sql("create temporary view tv2 as select * from tv1")
+              sql("insert into table ta values(1)")
+              sql("cache table ta")
+              sql("insert into table tb values(1)")
+              sql("cache table tb")
+
+              val qualifiedTaName = QualifiedTableName("default", "ta")
+              val cachedTa = 
spark.sessionState.catalog.getCachedTable(qualifiedTaName)
+
+              val qualifiedTbName = QualifiedTableName("default", "tb")
+              val cachedTb = 
spark.sessionState.catalog.getCachedTable(qualifiedTaName)
+
+              val newSession = spark.newSession()
+              newSession.sql(s"alter table ta set location 
'${dir1.getAbsolutePath}'")
+              newSession.sql("insert into table ta values(2)")
+              newSession.sql(s"alter table tb set location 
'${dir2.getAbsolutePath}'")
+              newSession.sql("insert into table tb values(2)")
+              newSession.sessionState.catalog.cacheTable(qualifiedTaName, 
cachedTa)

Review comment:
       because the new session shared the catalog with original spark session.
   And alter table set location command will invalid cached table, so I have to 
cache old cache info manually.




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



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

Reply via email to