uros-b commented on code in PR #57476:
URL: https://github.com/apache/spark/pull/57476#discussion_r3700458422


##########
sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala:
##########
@@ -324,6 +324,24 @@ class MathFunctionsSuite extends SharedSparkSession {
     testOneToOneMathFunction(rint, math.rint)
   }
 
+  test("truncate") {
+    val df = Seq(5, 55, 555).map(Tuple1(_)).toDF("a")
+    checkAnswer(
+      df.select(truncate($"a", lit(-1)), truncate($"a", lit(-2))),
+      Seq(Row(0, 0), Row(50, 0), Row(550, 500))
+    )
+    // Truncation rounds toward zero, unlike floor for negative values.
+    val df2 = Seq(1234.5678, -1234.5678).map(Tuple1(_)).toDF("a")
+    checkAnswer(
+      df2.select(truncate($"a", lit(2))),
+      Seq(Row(1234.56), Row(-1234.56))
+    )
+    checkAnswer(
+      df2.selectExpr("truncate(a, 2)"),
+      Seq(Row(1234.56), Row(-1234.56))
+    )
+  }
+

Review Comment:
   No decimal column goes through the DataFrame API. MathFunctionsSuite covers 
Int and Double only, yet Decimal is the path that required the new Decimal 
code. A decimal case there, and a NaN/Infinity double case since RoundBase 
special-cases those, would round it out.



-- 
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]

Reply via email to