File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change 1717
1818package org .apache .spark .sql .catalyst .expressions
1919
20- import java .sql .Date
21-
2220import org .apache .spark .SparkFunSuite
23- import org .apache .spark .sql .types . DateType
21+ import org .apache .spark .sql .catalyst . util . DateTimeUtils
2422
2523class 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}
You can’t perform that action at this time.
0 commit comments