Skip to content

Commit 50a7b41

Browse files
committed
Add tests to DateExpressionsSuite
1 parent d3b5764 commit 50a7b41

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.spark.sql.catalyst.expressions
1919

2020
import java.sql.{Date, Timestamp}
2121
import java.text.SimpleDateFormat
22-
import java.time.{LocalDateTime, ZoneId, ZoneOffset}
22+
import java.time.{LocalDateTime, LocalTime, ZoneId, ZoneOffset}
2323
import java.util.{Calendar, Locale, TimeZone}
2424
import java.util.concurrent.TimeUnit
2525
import java.util.concurrent.TimeUnit._
@@ -973,6 +973,28 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
973973
checkEvaluation(makeTimestampExpr, Timestamp.valueOf("2019-08-12 00:00:58.000001"))
974974
}
975975

976+
test("creating values of TimeType via make_time") {
977+
var makeTimeExpr = MakeTime(Literal(8), Literal(15), Literal(Decimal(BigDecimal(23.5), 8, 6)))
978+
val expected = LocalTime.parse("08:15:23.5")
979+
checkEvaluation(makeTimeExpr, expected)
980+
981+
checkEvaluation(makeTimeExpr.copy(hour = Literal.create(null, IntegerType)), null)
982+
checkEvaluation(makeTimeExpr.copy(hour = Literal(25)), null)
983+
984+
checkEvaluation(makeTimeExpr.copy(min = Literal.create(null, IntegerType)), null)
985+
checkEvaluation(makeTimeExpr.copy(min = Literal(65)), null)
986+
987+
checkEvaluation(makeTimeExpr.copy(sec = Literal.create(null, DecimalType(8, 6))), null)
988+
checkEvaluation(makeTimeExpr.copy(sec = Literal(Decimal(BigDecimal(70.0), 8, 6))), null)
989+
990+
makeTimeExpr = MakeTime(Literal(0), Literal(59), Literal(Decimal(BigDecimal(60.0), 8, 6)))
991+
checkEvaluation(makeTimeExpr, LocalTime.parse("01:00:00"))
992+
checkEvaluation(makeTimeExpr.copy(sec = Literal(Decimal(BigDecimal(60.5), 8, 6))), null)
993+
994+
makeTimeExpr = MakeTime(Literal(0), Literal(0), Literal(Decimal(BigDecimal(58.000001), 8, 6)))
995+
checkEvaluation(makeTimeExpr, LocalTime.parse("00:00:58.000001"))
996+
}
997+
976998
test("millennium") {
977999
val date = MakeDate(Literal(2019), Literal(1), Literal(1))
9781000
checkEvaluation(Millennium(date), 3)

0 commit comments

Comments
 (0)