Skip to content

Commit 27c9f95

Browse files
committed
refine tests..
1 parent e11ae75 commit 27c9f95

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DatetimeFunctionsSuite.scala

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,21 @@
1717

1818
package org.apache.spark.sql.catalyst.expressions
1919

20-
import java.sql.Date
21-
2220
import org.apache.spark.SparkFunSuite
23-
import org.apache.spark.sql.types.DateType
21+
import org.apache.spark.sql.catalyst.util.DateTimeUtils
2422

2523
class DatetimeFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
2624
test("datetime function current_date") {
27-
checkEvaluation(
28-
CurrentDate(),
29-
new Date(System.currentTimeMillis), EmptyRow)
25+
val d0 = DateTimeUtils.millisToDays(System.currentTimeMillis())
26+
val cd = CurrentDate().eval(EmptyRow).asInstanceOf[Int]
27+
val d1 = DateTimeUtils.millisToDays(System.currentTimeMillis())
28+
assert(d0 <= cd && cd <= d1 && d1 - d0 <= 1)
3029
}
3130

3231
test("datetime function current_timestamp") {
33-
// By the time we run check, current timestamp has been different.
34-
// So we just check the date part.
35-
checkEvaluation(
36-
Cast(CurrentTimestamp(), DateType),
37-
new Date(System.currentTimeMillis), EmptyRow)
32+
val ct = DateTimeUtils.toJavaTimestamp(CurrentTimestamp().eval(EmptyRow).asInstanceOf[Long])
33+
val t1 = System.currentTimeMillis()
34+
assert(math.abs(t1 - ct.getTime) < 5000)
3835
}
3936

4037
}

0 commit comments

Comments
 (0)