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_r368345078
 
 

 ##########
 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:
   @zero323, I think it's better to have only one function that takes columns. 
See:
   
   
https://github.com/apache/spark/blob/1f50a5875b46885a40668c058a1a28e736776244/sql/core/src/main/scala/org/apache/spark/sql/functions.scala#L57-L59

----------------------------------------------------------------
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]

Reply via email to