HyukjinKwon commented on code in PR #59466:
URL: https://github.com/apache/spark/pull/59466#discussion_r4289593524
##########
sql/core/src/test/scala/org/apache/spark/sql/MiscFunctionsSuite.scala:
##########
@@ -319,6 +319,27 @@ class MiscFunctionsSuite extends SharedSparkSession {
assert(math.abs(sum(0) - 4.0f) < 0.01f)
assert(math.abs(sum(1) - 6.0f) < 0.01f)
}
+
+ test("SPARK-60245: vector_sum preserves double precision in DataFrames") {
+ val df = Seq(Seq(16777216.0d, 1.0d), Seq(1.0d,
1e-8d)).toDF("v").repartition(2)
+ val result = df.select(vector_sum($"v"))
+ assertResult(ArrayType(DoubleType, containsNull =
false))(result.schema.head.dataType)
+ assertResult(Seq(16777217.0d,
1.00000001d))(result.head().getSeq[Double](0))
+ }
+
+ gridTest("SPARK-60245: observe vector aggregates")(Seq(
+ ("float", "vector_sum"),
+ ("double", "vector_sum"),
+ ("float", "vector_avg"))) { case (elementType, functionName) =>
+ val df = spark.range(0, 8, 1, 4).select(
+ array($"id".cast(elementType), lit(1).cast(elementType)).as("v"))
+ val aggregate = if (functionName == "vector_sum") vector_sum($"v") else
vector_avg($"v")
+ val expected = if (functionName == "vector_sum") Seq(28.0, 8.0) else
Seq(3.5, 1.0)
+ val observation = Observation(s"${functionName}_$elementType")
+
+ assertResult(8)(df.observe(observation,
aggregate.as("value")).collect().length)
+ assertResult(Map("value" -> expected))(observation.get)
Review Comment:
LGTM
--
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]