cloud-fan commented on a change in pull request #23259: [SPARK-26215][SQL]
Define reserved/non-reserved keywords based on the ANSI SQL standard
URL: https://github.com/apache/spark/pull/23259#discussion_r259228427
##########
File path:
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
##########
@@ -744,40 +750,69 @@ number
| MINUS? BIGDECIMAL_LITERAL #bigDecimalLiteral
;
+// NOTE: You must follow a rule below when you add a new ANTLR taken in this
file:
+// - All the ANTLR tokens = UNION(`ansiReserved`, `ansiNonReserved`) =
UNION(`reserved`, `nonReserved`)
+//
+// Let's say you add a new token `NEWTOKEN` and this is not reserved
regardless of a `spark.sql.parser.ansi.enabled`
+// value. In this case, you must add a token `NEWTOKEN` in both
`ansiNonReserved` and `nonReserved`.
+
+// A list of the reserved keywords below in Spark SQL. These keywords cannot
be used for identifiers
+// when `spark.sql.parser.ansi.enabled` = true. Currently, we only reserve the
ANSI keywords
+// that almost all the ANSI SQL standards (SQL-92, SQL-99, SQL-2003, SQL-2008,
SQL-2011, and SQL-2016)
+// and PostgreSQL reserve.
+ansiReserved
+ : ALL | AND | ANTI | ANY | AS | AUTHORIZATION | BOTH | CASE | CAST | CHECK
| COLLATE | COLUMN | CONSTRAINT | CREATE
+ | CROSS | CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP | CURRENT_USER |
DISTINCT | ELSE | END | EXCEPT | FALSE
+ | FETCH | FOR | FOREIGN | FROM | FULL | GRANT | GROUP | HAVING | IN |
INNER | INTERSECT | INTO | JOIN | IS
+ | LEADING | LEFT | NATURAL | NOT | NULL | ON | ONLY | OR | ORDER | OUTER |
OVERLAPS | PRIMARY | REFERENCES | RIGHT
+ | SELECT | SEMI | SESSION_USER | SETMINUS | SOME | TABLE | THEN | TO |
TRAILING | UNION | UNIQUE | USER | USING
+ | WHEN | WHERE | WITH
+ ;
+
+// When `spark.sql.parser.ansi.enabled` = true, the `ansiNonReserved` keywords
can be used for identifiers.
+// Otherwise (`spark.sql.parser.ansi.enabled` = false), we follow the existing
Spark SQL behaviour until v3.0:
Review comment:
```
The list of the non-reserved keywords when `spark.sql.parser.ansi.enabled`
is true.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]