HyukjinKwon commented on code in PR #41316:
URL: https://github.com/apache/spark/pull/41316#discussion_r1214001988


##########
python/pyspark/worker.py:
##########
@@ -456,6 +456,54 @@ def assign_cols_by_name(runner_conf):
     )
 
 
+def read_udtf(pickleSer, infile, eval_type):
+    num_udtfs = read_int(infile)
+    if num_udtfs != 1:
+        raise RuntimeError("Got more than 1 UDTF")
+
+    # See `PythonUDFRunner.writeUDFs`.
+    num_arg = read_int(infile)
+    arg_offsets = [read_int(infile) for _ in range(num_arg)]
+    num_chained_funcs = read_int(infile)
+    if num_chained_funcs != 1:
+        raise RuntimeError("Got more than 1 chained UDTF")
+
+    handler, return_type = read_command(pickleSer, infile)
+    if not isinstance(handler, type):
+        raise RuntimeError(f"UDTF handler must be a class, but got 
{type(handler)}.")
+
+    # Instantiate the UDTF class.
+    try:
+        udtf = handler()
+    except Exception as e:
+        raise RuntimeError(f"Failed to init the UDTF handler: {str(e)}") from 
None
+
+    # Wrap the eval method.
+    if not hasattr(udtf, "eval"):
+        raise RuntimeError("Python UDTF must implement the eval method.")
+
+    def wrap_udtf(f, return_type):
+        if return_type.needConversion():
+            toInternal = return_type.toInternal
+            return lambda *a: map(toInternal, f(*a))
+        else:
+            return lambda *a: f(*a)
+
+    f = wrap_udtf(getattr(udtf, "eval"), return_type)
+
+    def mapper(a):
+        results = tuple(f(*[a[o] for o in arg_offsets]))
+        return results
+
+    # Return an iterator of iterators.
+    def func(_, it):
+        return map(mapper, it)
+
+    ser = BatchedSerializer(CPickleSerializer(), 100)

Review Comment:
   no reason as far as I know. I think we picked this number like 10 years ago. 
BTW, we should better use Arrow one here.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to