pan3793 commented on code in PR #53129:
URL: https://github.com/apache/spark/pull/53129#discussion_r2541333882
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -695,12 +696,6 @@ class SparkSqlAstBuilder extends AstBuilder {
ctx.REPLACE != null,
finalSchemaBinding)
} else {
- // Disallows 'CREATE TEMPORARY VIEW IF NOT EXISTS' to be consistent with
- // 'CREATE TEMPORARY TABLE'
Review Comment:
the logic came from SPARK-6339 (2016), but seems without a clear reason
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala:
##########
@@ -586,17 +592,27 @@ abstract class SQLViewSuite extends QueryTest with
SQLTestUtils {
}
}
- test("correctly handle CREATE VIEW IF NOT EXISTS") {
- withTable("jt2") {
- withView("testView") {
- sql("CREATE VIEW testView AS SELECT id FROM jt")
-
- val df = (1 until 10).map(i => i -> i).toDF("i", "j")
- df.write.format("json").saveAsTable("jt2")
- sql("CREATE VIEW IF NOT EXISTS testView AS SELECT * FROM jt2")
-
- // make sure our view doesn't change.
- checkAnswer(sql("SELECT * FROM testView ORDER BY id"), (1 to 9).map(i
=> Row(i)))
+ test("correctly handle CREATE VIEW / TEMPORARY VIEW / GLOBAL TEMPORARY VIEW
IF NOT EXISTS") {
+ Seq("VIEW", "TEMPORARY VIEW", "GLOBAL TEMPORARY VIEW").foreach { viewType
=>
+ withTable("jt2") {
+ withView("testView") {
+ sql(s"CREATE $viewType testView AS SELECT id FROM jt")
+
+ val df = (1 until 10).map(i => i -> i).toDF("i", "j")
+ df.write.format("json").saveAsTable("jt2")
+ sql(s"CREATE $viewType IF NOT EXISTS testView AS SELECT * FROM jt2")
+
+ // make sure our view doesn't change.
+ val viewIdentifier = viewType match {
+ case "GLOBAL TEMPORARY VIEW" =>
+ TableIdentifier("testView",
Some(conf.getConf(GLOBAL_TEMP_DATABASE)))
Review Comment:
global temp view must be accessed via a qualified name.
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -997,6 +997,12 @@
],
"sqlState" : "0A000"
},
+ "CREATE_OR_REPLACE_WITH_IF_NOT_EXISTS_IS_NOT_ALLOWED" : {
+ "message" : [
+ "CREATE OR REPLACE <resourceType> with IF NOT EXISTS is not allowed."
Review Comment:
We can reuse this for other resource types, e.g. TABLE, FUNCTION, PROCEDURE
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]