cloud-fan commented on code in PR #43910:
URL: https://github.com/apache/spark/pull/43910#discussion_r1400103512
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/percentiles.scala:
##########
@@ -444,3 +444,81 @@ case class PercentileDisc(
}
}
}
+
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = "_FUNC_(percentage) WITHIN GROUP (ORDER BY col) - Return a
percentile value based on " +
+ "a continuous distribution of numeric or ANSI interval column `col` at the
given " +
+ "`percentage` (specified in ORDER BY clause).",
+ examples = """
+ Examples:
+ > SELECT _FUNC_(0.25) WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10)
AS tab(col);
+ 2.5
+ > SELECT _FUNC_(0.25) WITHIN GROUP (ORDER BY col) FROM VALUES (INTERVAL
'0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
+ 0-2
+ """,
+ group = "agg_funcs",
+ since = "4.0.0")
+// scalastyle:on line.size.limit
+object PercentileContBuilder extends ExpressionBuilder {
+ override def build(funcName: String, expressions: Seq[Expression]):
Expression = {
+ val numArgs = expressions.length
+ if (numArgs == 2) {
Review Comment:
For now, we implement WITHIN GROUP within the expression itself, instead of
a general approach. I think this will not be changed in the near future.
However, from the API perspective, WITHIN GROUP does like a general feature for
aggregate functions.
We should make the framework more flexible. My idea is
1. function lookup should only look at the function name and inputs, not
WITHIN GROUP (it's consistent with other features like DISTINCT, FILTER, etc.)
2. after function lookup, we get an expression, and the expression should
implement a trait to indicate that it supports `WITHIN GROUP`. Otherwise we
fail.
For example, we can have a
```
trait SupportsWithinGroup {
def withOrderings(orderings: Seq[SortOrder])
}
```
The two percentile expressions should implement this trait so that they can
get the orderings in a post-hoc way.
--
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]