Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/6938#discussion_r34648756
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
---
@@ -520,3 +522,204 @@ case class Logarithm(left: Expression, right:
Expression)
"""
}
}
+
+/**
+ * Round the `child`'s result to `scale` decimal place when `scale` >= 0
+ * or round at integral part when `scale` < 0.
+ * For example, round(31.415, 2) would eval to 31.42 and round(31.415, -1)
would eval to 30.
+ *
+ * Child of IntegralType would eval to itself when `scale` >= 0.
+ * Child of FractionalType whose value is NaN or Infinite would always
eval to itself.
+ *
+ * Round's dataType would always equal to `child`'s dataType except for
[[DecimalType.Fixed]],
+ * which leads to scale update in DecimalType's [[PrecisionInfo]]
+ *
+ * @param child expr to be round, all [[NumericType]] is allowed as Input
+ * @param scale new scale to be round to, this should be a constant int at
runtime
+ */
+case class Round(child: Expression, scale: Expression)
+ extends BinaryExpression with ExpectsInputTypes {
+
+ import BigDecimal.RoundingMode.HALF_UP
+
+ def this(child: Expression) = this(child, Literal(0))
+
+ override def left: Expression = child
+ override def right: Expression = scale
+
+ override def children: Seq[Expression] = Seq(child, scale)
--- End diff --
i don't think you need this
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]