iRakson commented on code in PR #57119:
URL: https://github.com/apache/spark/pull/57119#discussion_r3807579270
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameStatSuite.scala:
##########
@@ -605,6 +605,50 @@ class DataFrameStatSuite extends SharedSparkSession {
val df = spark.range(1).selectExpr("CAST(id as DECIMAL) as
x").selectExpr("percentile(x, 0.5)")
checkAnswer(df, Row(BigDecimal(0)) :: Nil)
}
+
+ test("SPARK-57849: DataFrame approxQuantile should support time type
columns") {
+ val df = sql(
+ "SELECT * FROM VALUES (CAST('06:00:00' AS TIME(9))), (CAST('06:00:00' AS
TIME(9))), " +
+ "(CAST('08:00:00' AS TIME(9))), (CAST('08:00:00' AS TIME(9))), " +
+ "(CAST('08:00:00' AS TIME(9))), (CAST('10:00:00' AS TIME(9)));"
+ )
+
+ val res = df.stat.approxQuantile("col1", Array(0.1, 0.5, 0.9), 0.01)
+ assert(res.length === 3)
+ assert(res.count(_.isNaN) === 0)
+ assert(res(1) === 28800.0)
+ }
+
+ test("SPARK-57849: DataFrame approxQuantile on TIME preserves sub-second
precision") {
+ val df = sql(
+ "SELECT * FROM VALUES (CAST('00:00:00.000000001' AS TIME(9))), " +
+ "(CAST('23:59:59.999999999' AS TIME(9)));"
+ )
+
+ val Array(min, max) = df.stat.approxQuantile("col1", Array(0.0, 1.0), 0.0)
+ assert(min === 1e-9 +- 1e-12)
+ assert(max === 86399.999999999 +- 1e-6)
+ }
+
+ test("SPARK-57849: summary() computes typed TIME percentiles") {
Review Comment:
added a new test case covering describe().
--
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]