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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala:
##########
@@ -1971,6 +1971,47 @@ case class BRound(
     newLeft: Expression, newRight: Expression): BRound = copy(child = newLeft, 
scale = newRight)
 }
 
+/**
+ * Truncate an expression toward zero to `scale` decimal places.
+ * A negative `scale` truncates digits to the left of the decimal point.
+ * truncate(1234.5678, 2) = 1234.56, truncate(-1234.5678, 2) = -1234.56.
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+  usage = "_FUNC_(expr[, scale]) - Returns `expr` truncated toward zero to 
`scale` decimal places. `scale` defaults to 0. A negative `scale` truncates 
digits to the left of the decimal point.",
+  arguments = """
+    Arguments:
+      * expr - The expression to truncate. An expression that evaluates to a 
numeric.
+      * scale - The number of decimal places to keep. An expression that 
evaluates to an integer, must be a constant, and defaults to 0. A negative 
value truncates digits to the left of the decimal point.
+  """,
+  examples = """
+    Examples:
+      > SELECT _FUNC_(1234.5678, 2);
+       1234.56
+      > SELECT _FUNC_(1234.5678, -2);
+       1200
+      > SELECT _FUNC_(-1234.5678, 2);
+       -1234.56
+  """,
+  since = "4.3.0",
+  group = "math_funcs")
+// scalastyle:on line.size.limit
+case class Truncate(
+    child: Expression,
+    scale: Expression,
+    override val ansiEnabled: Boolean = SQLConf.get.ansiEnabled)

Review Comment:
   ansiEnabled is inert for Truncate, it drags in MathUtils.withOverflow 
wrappers, the *ValueExact codegen variants, and query-context plumbing that can 
never fire, and it participates in canonicalized. Either drop it and let 
RoundBase's false default stand, or keep it for symmetry with a one-line 
comment saying overflow is impossible here.



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