uros-b commented on code in PR #56932:
URL: https://github.com/apache/spark/pull/56932#discussion_r3587916057
##########
sql/core/src/test/scala/org/apache/spark/sql/TimeFunctionsSuiteBase.scala:
##########
@@ -164,6 +164,49 @@ abstract class TimeFunctionsSuiteBase extends
SharedSparkSession {
checkAnswer(result2, expected)
}
+ test("SPARK-57846: try_make_time function") {
+ // Valid input data.
+ val schema = StructType(Seq(
+ StructField("hour", IntegerType, nullable = false),
+ StructField("minute", IntegerType, nullable = false),
+ StructField("second", DecimalType(16, 6), nullable = false)
+ ))
+ val data = Seq(
+ Row(0, 0, BigDecimal(0.0)),
+ Row(1, 2, BigDecimal(3.4)),
+ Row(23, 59, BigDecimal(59.999999))
+ )
+ val df = spark.createDataFrame(spark.sparkContext.parallelize(data),
schema)
+
+ // Test valid inputs using both selectExpr and select.
+ val result1 = df.selectExpr("try_make_time(hour, minute, second)")
+ val result2 = df.select(try_make_time(col("hour"), col("minute"),
col("second")))
+ checkAnswer(result1, result2)
+
+ val expected = Seq(
+ "00:00:00",
+ "01:02:03.4",
+ "23:59:59.999999"
+ ).toDF("timeString").select(col("timeString").cast("time"))
+ checkAnswer(result1, expected)
Review Comment:
Note about equivalence assertion strength: the integration test compares
valid output to a hardcoded string cast to time.
DateFunctionsSuite.try_make_timestamp instead asserts equivalence against
make_timestamp directly (checkAnswer(tryResult, makeResult) under
ANSI_ENABLED=false). Doing the same here (valid rows equal make_time) would
more directly express the "identical on valid input" contract.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]