Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/18323#discussion_r127595777
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
---
@@ -1186,3 +1186,51 @@ case class BRound(child: Expression, scale:
Expression)
with Serializable with ImplicitCastInputTypes {
def this(child: Expression) = this(child, Literal(0))
}
+
+/**
+ * Returns the bucket number into which
+ * the value of this expression would fall after being evaluated.
+ *
+ * @param expr is the expression for which the histogram is being created
+ * @param minValue is an expression that resolves
+ * to the minimum end point of the acceptable range for
expr
+ * @param maxValue is an expression that resolves
+ * to the maximum end point of the acceptable range for
expr
+ * @param numBucket is an An expression that resolves to
+ * a constant indicating the number of buckets
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = "_FUNC_(expr, min_value, max_value, num_bucket) - Returns an
long between 0 and `num_buckets`+1 by mapping the `expr` into buckets defined
by the range [`min_value`, `max_value`].",
+ extended = """
+ Examples:
+ > SELECT _FUNC_(5.35, 0.024, 10.06, 5);
+ 3
+ """)
+// scalastyle:on line.size.limit
+case class WidthBucket(
+ expr: Expression,
+ minValue: Expression,
+ maxValue: Expression,
+ numBucket: Expression) extends QuaternaryExpression with
ImplicitCastInputTypes {
+
+ override def children: Seq[Expression] = Seq(expr, minValue, maxValue,
numBucket)
+ override def inputTypes: Seq[AbstractDataType] = Seq(DoubleType,
DoubleType, DoubleType, LongType)
+ override def dataType: DataType = LongType
+ override def nullable: Boolean = true
+
+ override def nullSafeEval(ex: Any, min: Any, max: Any, num: Any): Any = {
+ MathUtils.widthBucket(
+ ex.asInstanceOf[Double],
--- End diff --
What happened if the input is not a constant, but an foldable expression?
---
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]