maropu commented on a change in pull request #23880: [SPARK-26976][SQL] Forbid 
reserved keywords as table identifiers when ANSI mode is on
URL: https://github.com/apache/spark/pull/23880#discussion_r259695200
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##########
 @@ -1404,6 +1404,15 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
     }
   }
 
+  override def visitIdentifier(ctx: IdentifierContext): String = 
withOrigin(ctx) {
+    val keyword = ctx.getText
+    if (ctx.ansiReserved() != null) {
+      throw new ParseException(
+        s"'$keyword' is reserved and you cannot use this keyword as an 
identifier.", ctx)
 
 Review comment:
   If we just remove the `(ansi)? ansiReservedKeywords` from `identifier`, all 
the rule using `identifier` can't accept reserved keywords. Is this expected?
   For example, we already `current_timestamp`/`current_date` as bulit-in 
functions in `FunctionRegistry`, but these keywords are reserved when ansi=true.
   
https://github.com/apache/spark/blob/2d2fb34b93a55af7e45191c8974bb55a0ed76e87/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4#L529

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to