zero323 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_r368511059
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/functions.scala
 ##########
 @@ -652,6 +652,122 @@ 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.0.0
+   */
+  def percentile_approx(e: Column, percentage: Array[Double], accuracy: Long): 
Column = {
+    withAggregateFunction {
+      new ApproximatePercentile(
+        e.expr, typedLit(percentage).expr, lit(accuracy).expr
+      )
+    }
+  }
+
+  /**
+   * 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.0.0
+   */
+  def percentile_approx(columnName: String, percentage: Array[Double], 
accuracy: Long): Column = {
+    percentile_approx(Column(columnName), percentage, accuracy)
+  }
+
+  /**
+   * 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.0.0
+   */
+  def percentile_approx(e: Column, percentage: Seq[Double], accuracy: Long): 
Column = {
+    percentile_approx(e, percentage.toArray, accuracy)
+  }
+
+  /**
+   * 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.0.0
+   */
+  def percentile_approx(columnName: String, percentage: Seq[Double], accuracy: 
Long): Column = {
+    percentile_approx(Column(columnName), percentage.toArray, accuracy)
+  }
+
+  /**
+   * Aggregate function: Returns the approximate percentile value of numeric
+   * column col at the given percentage.
+   *
+   * The value of percentage 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.0.0
+   */
+  def percentile_approx(e: Column, percentage: Double, accuracy: Long): Column 
= {
+    withAggregateFunction {
+      new ApproximatePercentile(
+        e.expr, lit(percentage).expr, lit(accuracy).expr
+      )
+    }
+  }
+
+  /**
+   * Aggregate function: Returns the approximate percentile value of numeric
+   * column col at the given percentage.
+   *
+   * The value of percentage 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.0.0
+   */
+  def percentile_approx(columnName: String, percentage: Double, accuracy: 
Long): Column = {
 
 Review comment:
   Do you mean we should remove variants `(String, _, _) -> Column` and leave 
only `(Column, _, _) -> Column`? Or rather replace all variants with `(Column, 
Column, Column) -> Column`?
   
   I'll be happy to do the former, but the latter is probably a bad idea:
   
   - Aggregation by group gets confusing. 
   - Array variants get somewhat painful to use for anyone but Scala users ‒ 
building array literal in Java is not fun. Same about non-JVM languages (and if 
we allow for non `Column` arguments then, complexity of wrappers grows).

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to