diff options
author | Herman van Hovell <hvanhovell@databricks.com> | 2016-08-02 10:09:47 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2016-08-02 10:09:47 -0700 |
commit | 2330f3ecbbd89c7eaab9cc0d06726aa743b16334 (patch) | |
tree | a92bd8441b13fa090a8c4f17fb402700aaefb674 /sql/core/src/test/scala | |
parent | 146001a9ffefc7aaedd3d888d68c7a9b80bca545 (diff) | |
download | spark-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/core/src/test/scala')
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala index 6e485a8f5b..8e7c8d7f07 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala @@ -18,7 +18,7 @@ package org.apache.spark.sql import java.math.MathContext -import java.sql.Timestamp +import java.sql.{Date, Timestamp} import org.apache.spark.{AccumulatorSuite, SparkException} import org.apache.spark.sql.catalyst.analysis.UnresolvedException @@ -3017,4 +3017,13 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { data.selectExpr("`part.col1`", "`col.1`")) } } + + test("current_date and current_timestamp literals") { + // NOTE that I am comparing the result of the literal with the result of the function call. + // This is done to prevent the test from failing because we are comparing a result to an out + // dated timestamp (quite likely) or date (very unlikely - but equally annoying). + checkAnswer( + sql("select current_date = current_date(), current_timestamp = current_timestamp()"), + Seq(Row(true, true))) + } } |