maropu commented on a change in pull request #24039: [SPARK-27117][SQL] 
current_date/current_timestamp should not refer to columns with ansi parser mode
URL: https://github.com/apache/spark/pull/24039#discussion_r264000845
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##########
 @@ -1212,6 +1212,21 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
     }
   }
 
+  override def visitCurrentDatetime(ctx: CurrentDatetimeContext): AnyRef = {
+    if (conf.ansiParserEnabled) {
+      ctx.name.getType match {
+        case SqlBaseParser.CURRENT_DATE =>
+          CurrentDate()
+        case SqlBaseParser.CURRENT_TIMESTAMP =>
+          CurrentTimestamp()
+      }
+    } else {
+      // If the parser is not in ansi mode, we should return 
`UnresolvedAttribute`, in case there
+      // are columns named `CURRENT_DATE` or `CURRENT_TIMESTAMP`.
+      UnresolvedAttribute.quoted(ctx.name.getText)
+    }
+  }
+
 
 Review comment:
   We need to change the current behaviour of `select current_date`/`select 
current_timestamp` in the non-ansi mode? If so, we need to update the migration 
guide:
   ```
   // the current behaivour in the non-ansi mode
   scala> sql("SET spark.sql.parser.ansi.enabled=false")
   scala> sql("SELECT CURRENT_TIMESTAMP").show
   +--------------------+                                                       
   
   | current_timestamp()|
   +--------------------+
   |2019-02-25 16:26:...|
   +--------------------+
   ```

----------------------------------------------------------------
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.
 
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]

Reply via email to