Skip to content

Commit

Permalink
Test for current_date, current_timestamp and now (#3282)
Browse files Browse the repository at this point in the history
Signed-off-by: Shane Ding <shane200195@gmail.com>
  • Loading branch information
shaneding authored Aug 25, 2021
1 parent e94afd9 commit 4cc1d89
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down

0 comments on commit 4cc1d89

Please sign in to comment.