nchammas commented on a change in pull request #27406: 
[SPARK-30681][PYSPARK][SQL] Add higher order functions API to PySpark
URL: https://github.com/apache/spark/pull/27406#discussion_r373158241
 
 

 ##########
 File path: python/pyspark/sql/functions.py
 ##########
 @@ -2840,6 +2840,359 @@ def from_csv(col, schema, options={}):
     return Column(jc)
 
 
+def _invoke_higher_order_function(name):
+    """
+    Given name of the expression corresponding to a higher order SQL function,
+    return a function that takes
+
+    - a list of columns
+    - a list of functions (*Column) -> Column
+
+    invokes expression, and wraps result in a Column
+    (first Scala one, then Python).
+    """
+
+    def _(cols, funs):
+        sc = SparkContext._active_spark_context
+        expressions = sc._jvm.org.apache.spark.sql.catalyst.expressions
+        expr = getattr(expressions, name)
+
+        jcols = [_to_java_column(col).expr() for col in cols]
+        jfuns = [_create_lambda(f) for f in funs]
+
+        return Column(sc._jvm.Column(expr(*jcols + jfuns)))
+
+    return _
+
+
+@since(3.0)
+def transform(col, f):
+    """
+    Returns an array of elements after applying a transformation to each 
element in the input array.
+
+    :param col: name of column or expression
+    :param f: a function that is applied to each element of the input array.
+        Can take one of the following forms:
+
+        - Unary ``(x: Column) -> Column: ...``
+        - Binary ``(x: Column, i: Column) -> Column...``, where the second 
argument is
+            a 0-based index of the element.
+
+        and an use methods of :class:`pyspark.sql.Column`, functions defined in
+        :py:mod:`pyspark.sql.functions` and Scala ``UserDefinedFunctions``.
+        Python ``UserDefinedFunctions`` are not supported
+        (`SPARK-27052 <https://issues.apache.org/jira/browse/SPARK-27052>`__).
+
+    :return: a :class:`pyspark.sql.Column`
+
+    >>> df = spark.createDataFrame([(1, [1, 2, 3, 4])],("key", "values"))
 
 Review comment:
   Whitespace nit: `, ("key`

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