aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main/scala/org
diff options
context:
space:
mode:
authorHerman van Hovell <hvanhovell@databricks.com>2016-08-02 10:09:47 -0700
committerReynold Xin <rxin@databricks.com>2016-08-02 10:09:47 -0700
commit2330f3ecbbd89c7eaab9cc0d06726aa743b16334 (patch)
treea92bd8441b13fa090a8c4f17fb402700aaefb674 /sql/catalyst/src/main/scala/org
parent146001a9ffefc7aaedd3d888d68c7a9b80bca545 (diff)
downloadspark-2330f3ecbbd89c7eaab9cc0d06726aa743b16334.tar.gz
spark-2330f3ecbbd89c7eaab9cc0d06726aa743b16334.tar.bz2
spark-2330f3ecbbd89c7eaab9cc0d06726aa743b16334.zip
[SPARK-16836][SQL] Add support for CURRENT_DATE/CURRENT_TIMESTAMP literals
## What changes were proposed in this pull request? In Spark 1.6 (with Hive support) we could use `CURRENT_DATE` and `CURRENT_TIMESTAMP` functions as literals (without adding braces), for example: ```SQL select /* Spark 1.6: */ current_date, /* Spark 1.6 & Spark 2.0: */ current_date() ``` This was accidentally dropped in Spark 2.0. This PR reinstates this functionality. ## How was this patch tested? Added a case to ExpressionParserSuite. Author: Herman van Hovell <hvanhovell@databricks.com> Closes #14442 from hvanhovell/SPARK-16836.
Diffstat (limited to 'sql/catalyst/src/main/scala/org')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala13
1 files changed, 13 insertions, 0 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
index f2cc8d3624..679adf2717 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
@@ -1023,6 +1023,19 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with Logging {
}
/**
+ * Create a current timestamp/date expression. These are different from regular function because
+ * they do not require the user to specify braces when calling them.
+ */
+ override def visitTimeFunctionCall(ctx: TimeFunctionCallContext): Expression = withOrigin(ctx) {
+ ctx.name.getType match {
+ case SqlBaseParser.CURRENT_DATE =>
+ CurrentDate()
+ case SqlBaseParser.CURRENT_TIMESTAMP =>
+ CurrentTimestamp()
+ }
+ }
+
+ /**
* Create a function database (optional) and name pair.
*/
protected def visitFunctionName(ctx: QualifiedNameContext): FunctionIdentifier = {