Skip to content

Commit 6e78983

Browse files
committed
[SPARK-53924][FOLLOWUP][TESTS] Add tests for cached temp view detecting schema changes
### What changes were proposed in this pull request? Follow-up of #52876, add tests for cached temp view detecting schema changes ### Why are the changes needed? There is no test coverage after comment #52876 (comment) is addressed. This PR is to add a test case for it. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? New test case ### Was this patch authored or co-authored using generative AI tooling? No Closes #53103 from gengliangwang/SPARK-53924-test. Authored-by: Gengliang Wang <gengliang@apache.org> Signed-off-by: Gengliang Wang <gengliang@apache.org> (cherry picked from commit fd683ce) Signed-off-by: Gengliang Wang <gengliang@apache.org>
1 parent 505d5f0 commit 6e78983

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2DataFrameSuite.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,34 @@ class DataSourceV2DataFrameSuite
11731173
}
11741174
}
11751175

1176+
test("SPARK-54157: cached temp view detects schema changes after analysis") {
1177+
val t = "testcat.ns1.ns2.tbl"
1178+
withTable(t) {
1179+
sql(s"CREATE TABLE $t (id INT, data STRING) USING foo")
1180+
sql(s"INSERT INTO $t VALUES (1, 'a')")
1181+
1182+
// create a temp view on top of the DSv2 table and cache the view
1183+
spark.table(t).createOrReplaceTempView("v")
1184+
sql("CACHE TABLE v")
1185+
assertCached(sql("SELECT * FROM v"))
1186+
1187+
// change table schema after the view has been analyzed and cached
1188+
sql(s"ALTER TABLE $t ADD COLUMN extra INT")
1189+
1190+
// execution should fail with column mismatch even though the view is cached
1191+
checkError(
1192+
exception = intercept[AnalysisException] { spark.table("v").collect() },
1193+
condition = "INCOMPATIBLE_COLUMN_CHANGES_AFTER_VIEW_WITH_PLAN_CREATION",
1194+
parameters = Map(
1195+
"viewName" -> "`v`",
1196+
"tableName" -> "`testcat`.`ns1`.`ns2`.`tbl`",
1197+
"colType" -> "data",
1198+
"errors" ->
1199+
"""
1200+
|- `extra` INT has been added""".stripMargin))
1201+
}
1202+
}
1203+
11761204
test("SPARK-54157: detect nested struct field changes after DataFrame analysis") {
11771205
val t = "testcat.ns1.ns2.tbl"
11781206
withTable(t) {

0 commit comments

Comments
 (0)