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_r269973264
 
 

 ##########
 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:
   Actually a better idea would probably be to use java functional interfaces.
   
   ```java
   @FuncitonalInterface
   interface Function3[T1, T2, T3, R] {
     R apply(T1 t1, T2 t2, T3 t3);
   }
   
   Column exists(Column column, Function3[Column, Column, Column, Column] f) = 
...
   ```

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