From 4cc1d897a527759c4f4462e4a46e9d9c7d913327 Mon Sep 17 00:00:00 2001 From: shaneding Date: Wed, 25 Aug 2021 10:14:44 -0400 Subject: [PATCH] Test for `current_date`, `current_timestamp` and `now` (#3282) Signed-off-by: Shane Ding --- .../spark/rapids/ParseDateTimeSuite.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/src/test/scala/com/nvidia/spark/rapids/ParseDateTimeSuite.scala b/tests/src/test/scala/com/nvidia/spark/rapids/ParseDateTimeSuite.scala index 45ecbd8af1b..63d2c8d6b6f 100644 --- a/tests/src/test/scala/com/nvidia/spark/rapids/ParseDateTimeSuite.scala +++ b/tests/src/test/scala/com/nvidia/spark/rapids/ParseDateTimeSuite.scala @@ -357,6 +357,24 @@ class ParseDateTimeSuite extends SparkQueryCompareTestSuite with BeforeAndAfterE } } + test("literals: ensure time literals are correct") { + val conf = new SparkConf() + val df = withGpuSparkSession(spark => { + spark.sql("SELECT current_date(), current_timestamp(), now() FROM RANGE(1, 10)") + }, conf) + + val times = df.collect() + val systemCurrentTime = System.currentTimeMillis() + val res = times.forall(time => { + val diffDate = systemCurrentTime - time.getDate(0).getTime() + val diffTimestamp = systemCurrentTime - time.getTimestamp(1).getTime() + val diffNow = systemCurrentTime - time.getTimestamp(2).getTime() + diffDate.abs <= 8.64E7 & diffTimestamp.abs <= 1000 & diffNow.abs <= 1000 + }) + + assert(res) + } + private def testRegex(rule: RegexReplace, values: Seq[String], expected: Seq[String]): Unit = { withResource(ColumnVector.fromStrings(values: _*)) { v => withResource(ColumnVector.fromStrings(expected: _*)) { expected =>