pan3793 commented on code in PR #53129:
URL: https://github.com/apache/spark/pull/53129#discussion_r2633805729
##########
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:
They have different behaviors:
TABLE - antlr raises a syntax error due to we have special g4 definitions
for it
```
createTableHeader
: CREATE TEMPORARY? EXTERNAL? TABLE (IF errorCapturingNot EXISTS)?
identifierReference
;
replaceTableHeader
: (CREATE OR)? REPLACE TABLE identifierReference
;
```
while other resources are basically defined by
```
CREATE (OR REPLACE)? XYZ (IF errorCapturingNot EXISTS)? identifierReference
```
So TABLE fails with `PARSE_SYNTAX_ERROR`, other resources fail later.
---
Examples:
```
spark-sql (default)> CREATE OR REPLACE TABLE IF NOT EXISTS t (id INT);
[PARSE_SYNTAX_ERROR] Syntax error at or near 'NOT'. SQLSTATE: 42601 (line 1,
pos 27)
== SQL ==
CREATE OR REPLACE TABLE IF NOT EXISTS t (id INT)
---------------------------^^^
spark-sql (default)> CREATE OR REPLACE TEMPORARY FUNCTION IF NOT EXISTS
hello() RETURNS STRING RETURN 'Hello World!';
[INVALID_SQL_SYNTAX.CREATE_ROUTINE_WITH_IF_NOT_EXISTS_AND_REPLACE] Invalid
SQL syntax: Cannot create a routine with both IF NOT EXISTS and REPLACE
specified. SQLSTATE: 42000
== SQL (line 1, position 1) ==
CREATE OR REPLACE TEMPORARY FUNCTION IF NOT EXISTS hello() RETURNS STRING
RETURN 'Hello World!'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spark-sql (default)> CREATE OR REPLACE VIEW IF NOT EXISTS v AS SELECT 1;
CREATE VIEW with both IF NOT EXISTS and REPLACE is not allowed.
== SQL (line 1, position 1) ==
CREATE OR REPLACE VIEW IF NOT EXISTS v AS SELECT 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spark-sql (default)> CREATE OR REPLACE TEMPORARY VIEW IF NOT EXISTS v AS
SELECT 1;
CREATE VIEW with both IF NOT EXISTS and REPLACE is not allowed.
== SQL (line 1, position 1) ==
CREATE OR REPLACE TEMPORARY VIEW IF NOT EXISTS v AS SELECT 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
--
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]