HyukjinKwon commented on a change in pull request #27278:
[SPARK-30569][SQL][PYSPARK][SPARKR] Add percentile_approx DSL functions.
URL: https://github.com/apache/spark/pull/27278#discussion_r385499333
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/functions.scala
##########
@@ -652,6 +652,50 @@ object functions {
*/
def min(columnName: String): Column = min(Column(columnName))
+ /**
+ * Aggregate function: Returns and array of the approximate percentile values
+ * of numeric column col at the given percentages.
+ *
+ * Each value of the percentage array must be between 0.0 and 1.0.
+ *
+ * The accuracy parameter is a positive numeric literal
+ * which controls approximation accuracy at the cost of memory.
+ * Higher value of accuracy yields better accuracy, 1.0/accuracy
+ * is the relative error of the approximation.
+ *
+ * @group agg_funcs
+ * @since 3.1.0
+ */
+ def percentile_approx(e: Column, percentage: Array[Double], accuracy: Long):
Column = {
Review comment:
Seems like the percentiles can at least be foldable expressions, e.g.:
```scala
scala> sql("select percentile_approx(1, 0.5 + 0.5)")
res5: org.apache.spark.sql.DataFrame = [percentile_approx(1, CAST((CAST(0.5
AS DECIMAL(2,1)) + CAST(0.5 AS DECIMAL(2,1))) AS DOUBLE), 10000): int]
```
I know it's pretty unlikely but still possible given that we have a set of
foldable expressions. The error message isn't completely correct because it can
accept other foldable expressions.
Other variants were not changed only due to the legacy reason.
I think we would have not had such arguments all signatures were with
`Column` at the very first place in `functions.scala`.
Also, it's completely no problem for any one in the community to say out
what they think is right .. :-). We just need to chime in which I think I am
not pretty good at 😢.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]