MaxGekk commented on code in PR #50194: URL: https://github.com/apache/spark/pull/50194#discussion_r1990554669
########## sql/core/src/test/scala/org/apache/spark/sql/UDFSuite.scala: ########## @@ -1197,6 +1197,35 @@ class UDFSuite extends QueryTest with SharedSparkSession { Row(Row(null))) } + test("SPARK-51402: Test TimeType in UDF") { + // Mocks + val mockTimeStr = "00:00:00.000000" + val input = Seq(java.time.LocalTime.parse(mockTimeStr)).toDF("currentTime") Review Comment: Could you import java.time.LocalTime above: ```scala import java.time.{Instant, LocalDate, LocalTime} ``` This should improve test readability. ########## sql/core/src/test/scala/org/apache/spark/sql/UDFSuite.scala: ########## @@ -1197,6 +1197,35 @@ class UDFSuite extends QueryTest with SharedSparkSession { Row(Row(null))) } + test("SPARK-51402: Test TimeType in UDF") { + // Mocks + val mockTimeStr = "00:00:00.000000" + val input = Seq(java.time.LocalTime.parse(mockTimeStr)).toDF("currentTime") + // Regular case + val plusHour = udf((l: java.time.LocalTime) => l.plusHours(1)) + val result = input.select(plusHour($"currentTime").as("newTime")) + checkAnswer(result, Row(java.time.LocalTime.parse("01:00:00.000000")) :: Nil) + assert(result.schema === new StructType().add("newTime", TimeType())) + // UDF produces `null` + val nullFunc = udf((_: java.time.LocalTime) => null.asInstanceOf[java.time.LocalTime]) + val nullResult = input.select(nullFunc($"currentTime").as("nullTime")) + checkAnswer(nullResult, Row(null) :: Nil) + assert(nullResult.schema === new StructType().add("nullTime", TimeType())) + // Input parameter of UDF is null + val nullInput = Seq(null.asInstanceOf[java.time.LocalTime]).toDF("nullTime") + val constDuration = udf((_: java.time.LocalTime) => Review Comment: ```suggestion val constTime = udf((_: java.time.LocalTime) => ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org