Skip to content

Commit 1cd1cb3

Browse files
committed
add error message check
1 parent f8564cb commit 1cd1cb3

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,32 +3945,39 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
39453945
}
39463946

39473947
test("SPARK-34421: Resolve temporary functions and views in views with CTEs") {
3948-
withTempView("temp_view") {
3948+
val tempViewName = "temp_view"
3949+
3950+
withTempView(tempViewName) {
39493951
spark.udf.register("temp_func", identity[Int](_))
39503952

39513953
sql(
39523954
s"""
3953-
|CREATE TEMPORARY VIEW temp_view AS
3955+
|CREATE TEMPORARY VIEW $tempViewName AS
39543956
|WITH cte AS (
39553957
| SELECT temp_func(0)
39563958
|)
39573959
|SELECT * FROM cte
39583960
|""".stripMargin)
3959-
checkAnswer(sql("SELECT * FROM temp_view"), Row(0))
3961+
checkAnswer(sql(s"SELECT * FROM $tempViewName"), Row(0))
39603962
}
3961-
withTempView("temp_view") {
3962-
sql("CREATE TEMPORARY VIEW temp_view AS SELECT 0")
39633963

3964-
intercept[AnalysisException] {
3964+
withTempView(tempViewName) {
3965+
sql(s"CREATE TEMPORARY VIEW $tempViewName AS SELECT 0")
3966+
3967+
val viewName = "view_on_temp_view"
3968+
3969+
val e = intercept[AnalysisException] {
39653970
sql(
3966-
"""
3967-
|CREATE VIEW view_on_temp_view AS
3971+
s"""
3972+
|CREATE VIEW $viewName AS
39683973
|WITH cte AS (
3969-
| SELECT * FROM temp_view
3974+
| SELECT * FROM $tempViewName
39703975
|)
39713976
|SELECT * FROM cte
39723977
|""".stripMargin)
39733978
}
3979+
assert(e.message.contains(s"Not allowed to create a permanent view `default`.`$viewName` " +
3980+
s"by referencing a temporary view $tempViewName."))
39743981
}
39753982
}
39763983
}

0 commit comments

Comments
 (0)