cloud-fan commented on code in PR #57476:
URL: https://github.com/apache/spark/pull/57476#discussion_r3746490229
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala:
##########
@@ -1971,6 +1971,51 @@ 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.
Review Comment:
```suggestion
* scale - The number of decimal places to keep. It must be a constant
integer expression and defaults to 0. A negative value truncates digits to the
left of the decimal point.
```
##########
sql/api/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -6069,6 +6069,50 @@ object functions {
*/
def round(e: Column, scale: Column): Column = Column.fn("round", e, scale)
+ /**
+ * Truncates the value of `e` toward zero to 0 decimal places.
+ *
+ * @param e
+ * the value to truncate. A column that evaluates to a numeric.
+ * @return
+ * Returns a column of the same type as the input.
Review Comment:
Decimal inputs do not necessarily keep the same Spark SQL type: `RoundBase`
derives new precision and scale from the requested scale. Please mirror the
Python wording here and in the other two overloads: the type is preserved
except that decimal precision and scale may change.
--
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]