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


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala:
##########
@@ -727,6 +727,27 @@ class MathExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
     checkConsistencyBetweenInterpretedAndCodegen(Logarithm, DoubleType, 
DoubleType)
   }
 
+  test("truncate") {
+    // Truncation toward zero, distinct from floor/ceil (toward -inf/+inf) and 
round (to nearest).
+    checkEvaluation(Truncate(Literal(Decimal(BigDecimal("1234.5678"))), 
Literal(2)),
+      Decimal(BigDecimal("1234.56")))
+    checkEvaluation(Truncate(Literal(Decimal(BigDecimal("-1234.5678"))), 
Literal(2)),
+      Decimal(BigDecimal("-1234.56")))
+    checkEvaluation(Truncate(Literal(Decimal(BigDecimal("1234.5678"))), 
Literal(-2)),
+      Decimal(BigDecimal("1200")))
+    checkEvaluation(Truncate(Literal(Decimal(BigDecimal("-3.99"))), 
Literal(0)),
+      Decimal(BigDecimal("-3")))
+    // Default scale is 0.
+    checkEvaluation(new Truncate(Literal(Decimal(BigDecimal("3.99")))), 
Decimal(BigDecimal("3")))
+    // Integral input with negative scale.
+    checkEvaluation(Truncate(Literal(125), Literal(-1)), 120)
+    // Double input.
+    checkEvaluation(Truncate(Literal(3.1415926), Literal(3)), 3.141)
+    // Null propagation.
+    checkEvaluation(Truncate(Literal.create(null, DoubleType), Literal(2)), 
null)
+    checkEvaluation(Truncate(Literal(1.23), Literal.create(null, 
IntegerType)), null)
+  }
+

Review Comment:
   The one-argument form is never exercised end-to-end. MathExpressionsSuite 
builds new Truncate(Literal(...)) directly, which bypasses the function 
registry, and every SQL query, doctest, and DataFrame call passes an explicit 
scale. Since the usage string advertises _FUNC_(expr[, scale]), add SELECT 
truncate(1234.5678); to math.sql or as a fourth ExpressionDescription example 
(those are executed by ExpressionInfoSuite), plus a PySpark doctest that omits 
scale.



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