This is an automated email from the ASF dual-hosted git repository.
allisonwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 972897433082 [SPARK-55822][SQL] Rename `_LEGACY_ERROR_TEMP_0052` to
`CREATE_VIEW_WITH_IF_NOT_EXISTS_AND_REPLACE`
972897433082 is described below
commit 972897433082b1a7136b877b4fa37970961169d0
Author: ilicmarkodb <[email protected]>
AuthorDate: Thu Mar 5 12:39:15 2026 -0800
[SPARK-55822][SQL] Rename `_LEGACY_ERROR_TEMP_0052` to
`CREATE_VIEW_WITH_IF_NOT_EXISTS_AND_REPLACE`
### What changes were proposed in this pull request?
Rename the legacy error class `_LEGACY_ERROR_TEMP_0052` to a proper
descriptive name `CREATE_VIEW_WITH_IF_NOT_EXISTS_AND_REPLACE` and add SQL state
42601 (syntax error - conflicting SQL clauses).
This error is thrown when CREATE VIEW is used with both IF NOT EXISTS and
REPLACE simultaneously.
### Why are the changes needed?
Proper error messaging.
### Does this PR introduce _any_ user-facing change?
Yes. The error class name changes from `_LEGACY_ERROR_TEMP_0052` to
`CREATE_VIEW_WITH_IF_NOT_EXISTS_AND_REPLACE`, and the SQL state `42601` is now
included.
### How was this patch tested?
New unit test.
### Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored with Claude Code
Closes #54606 from ilicmarkodb/remove__LEGACY_ERROR_TEMP_0052.
Authored-by: ilicmarkodb <[email protected]>
Signed-off-by: Allison Wang <[email protected]>
---
.../src/main/resources/error/error-conditions.json | 11 ++++++-----
.../apache/spark/sql/errors/QueryParsingErrors.scala | 9 +++++++--
.../org/apache/spark/sql/execution/SparkSqlParser.scala | 6 ++++--
.../org/apache/spark/sql/execution/SQLViewSuite.scala | 17 ++++++++++++-----
4 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/common/utils/src/main/resources/error/error-conditions.json
b/common/utils/src/main/resources/error/error-conditions.json
index b5b4115bf746..2a7c98b27af8 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -1049,6 +1049,12 @@
},
"sqlState" : "21S01"
},
+ "CREATE_VIEW_WITH_IF_NOT_EXISTS_AND_REPLACE" : {
+ "message" : [
+ "CREATE VIEW <viewName> with both IF NOT EXISTS and REPLACE is not
allowed."
+ ],
+ "sqlState" : "42601"
+ },
"CURSOR_ALREADY_EXISTS" : {
"message" : [
"Cannot declare cursor <cursorName> because it already exists in the
current scope."
@@ -8036,11 +8042,6 @@
"Empty set in <element> grouping sets is not supported."
]
},
- "_LEGACY_ERROR_TEMP_0052" : {
- "message" : [
- "CREATE VIEW with both IF NOT EXISTS and REPLACE is not allowed."
- ]
- },
"_LEGACY_ERROR_TEMP_0053" : {
"message" : [
"It is not allowed to define a TEMPORARY view with IF NOT EXISTS."
diff --git
a/sql/api/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
b/sql/api/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
index 67f89e996da2..b19198d8b577 100644
---
a/sql/api/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
+++
b/sql/api/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
@@ -625,8 +625,13 @@ private[sql] object QueryParsingErrors extends
DataTypeErrorsBase {
ctx)
}
- def createViewWithBothIfNotExistsAndReplaceError(ctx: ParserRuleContext):
Throwable = {
- new ParseException(errorClass = "_LEGACY_ERROR_TEMP_0052", ctx)
+ def createViewWithBothIfNotExistsAndReplaceError(
+ viewName: String,
+ ctx: ParserRuleContext): Throwable = {
+ new ParseException(
+ errorClass = "CREATE_VIEW_WITH_IF_NOT_EXISTS_AND_REPLACE",
+ messageParameters = Map("viewName" -> viewName),
+ ctx)
}
def temporaryViewWithSchemaBindingMode(ctx: StatementContext): Throwable = {
diff --git
a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
index 4c6df5dbe6cf..b024c6d1f0aa 100644
---
a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
+++
b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
@@ -685,7 +685,8 @@ class SparkSqlAstBuilder extends AstBuilder {
}
if (ctx.EXISTS != null && ctx.REPLACE != null) {
- throw
QueryParsingErrors.createViewWithBothIfNotExistsAndReplaceError(ctx)
+ throw QueryParsingErrors.createViewWithBothIfNotExistsAndReplaceError(
+ ctx.identifierReference().getText, ctx)
}
val properties =
ctx.propertyList.asScala.headOption.map(visitPropertyKeyValues)
@@ -778,7 +779,8 @@ class SparkSqlAstBuilder extends AstBuilder {
}
if (ctx.EXISTS != null && ctx.REPLACE != null) {
- throw
QueryParsingErrors.createViewWithBothIfNotExistsAndReplaceError(ctx)
+ throw QueryParsingErrors.createViewWithBothIfNotExistsAndReplaceError(
+ ctx.identifierReference().getText, ctx)
}
if (ctx.METRICS(0) == null) {
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
index 050a004a9353..20441a54a223 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
@@ -627,11 +627,18 @@ abstract class SQLViewSuite extends QueryTest with
SQLTestUtils {
sql("DROP VIEW testView")
- val e = intercept[ParseException] {
- sql("CREATE OR REPLACE VIEW IF NOT EXISTS testView AS SELECT id FROM
jt")
- }
- assert(e.message.contains(
- "CREATE VIEW with both IF NOT EXISTS and REPLACE is not allowed"))
+ val sqlText = "CREATE OR REPLACE VIEW IF NOT EXISTS testView AS SELECT
id FROM jt"
+ checkError(
+ exception = intercept[ParseException] {
+ sql(sqlText)
+ },
+ condition = "CREATE_VIEW_WITH_IF_NOT_EXISTS_AND_REPLACE",
+ sqlState = "42601",
+ parameters = Map("viewName" -> "testView"),
+ context = ExpectedContext(
+ fragment = sqlText,
+ start = 0,
+ stop = sqlText.length - 1))
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]