nvander1 commented on a change in pull request #24232: [SPARK-27297] [SQL] Add 
higher order functions to scala API
URL: https://github.com/apache/spark/pull/24232#discussion_r269973574
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/functions.scala
 ##########
 @@ -3316,6 +3316,141 @@ object functions {
     ArrayExcept(col1.expr, col2.expr)
   }
 
+  private def expressionFunction(f: Column => Column)
+  : Expression => Expression =
+    x => f(Column(x)).expr
+
+  private def expressionFunction(f: (Column, Column) => Column)
+  : (Expression, Expression) => Expression =
+    (x, y) => f(Column(x), Column(y)).expr
+
+  private def expressionFunction(f: (Column, Column, Column) => Column)
+  : (Expression, Expression, Expression) => Expression =
+    (x, y, z) => f(Column(x), Column(y), Column(z)).expr
+
+  /**
+   * Returns an array of elements after applying a tranformation to each 
element
+   * in the input array.
+   *
+   * @group collection_funcs
+   */
+  def transform(column: Column, f: Column => Column): Column = withExpr {
+    HigherOrderUtils.transform(column.expr, expressionFunction(f))
+  }
+
+  /**
+   * Returns an array of elements after applying a tranformation to each 
element
+   * in the input array.
+   *
+   * @group collection_funcs
+   */
+  def transform(column: Column, f: (Column, Column) => Column): Column = 
withExpr {
+    HigherOrderUtils.transform(column.expr, expressionFunction(f))
+  }
+
+  /**
+   * Returns whether a predicate holds for one or more elements in the array.
+   *
+   * @group collection_funcs
+   */
+  def exists(column: Column, f: Column => Column): Column = withExpr {
 
 Review comment:
   And of course we would use the existing functional interfaces first from 
`java.util.function`, but I don't think there are any that accept three 
parameters likes some of the functions here require.

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