WweiL commented on code in PR #46002:
URL: https://github.com/apache/spark/pull/46002#discussion_r1561567073


##########
python/pyspark/sql/connect/streaming/readwriter.py:
##########
@@ -535,14 +535,16 @@ def foreach(self, f: "SupportsProcess") -> 
"DataStreamWriter":
 
     def foreach(self, f: Union[Callable[[Row], None], "SupportsProcess"]) -> 
"DataStreamWriter":
         from pyspark.serializers import CPickleSerializer, 
AutoBatchedSerializer
+        from pyspark.sql.connect.session import SparkSession
 
         func = PySparkDataStreamWriter._construct_foreach_function(f)
         serializer = AutoBatchedSerializer(CPickleSerializer())
         command = (func, None, serializer, serializer)
+        dispatch_handlers = {SparkSession: lambda x: 
x.__custom_reduce_handler__()}
         # Python ForeachWriter isn't really a PythonUDF. But we reuse it for 
simplicity.
         try:
             self._write_proto.foreach_writer.python_function.command = (
-                CloudPickleSerializer().dumps(command)
+                CloudPickleSerializer().dumps(command, 
dispatch_handlers=dispatch_handlers)

Review Comment:
   foreach is like a udf running on the executors, the behavior should be 
aligned with UDFs?



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