ueshin opened a new pull request, #42135:
URL: https://github.com/apache/spark/pull/42135

   ### What changes were proposed in this pull request?
   
   Adds support for `accumulator`, `broadcast` for vanilla PySpark, and Spark 
files for both vanilla PySpark and Spark Connect Python client, in Python 
UDTF's analyze.
   
   For example, in vanilla PySpark:
   
   ```py
   >>> colname = sc.broadcast("col1")
   >>> test_accum = sc.accumulator(0)
   
   >>> @udtf
   ... class TestUDTF:
   ...     @staticmethod
   ...     def analyze(a: AnalyzeArgument) -> AnalyzeResult:
   ...         test_accum.add(1)
   ...         return AnalyzeResult(StructType().add(colname.value, 
a.data_type))
   ...     def eval(self, a):
   ...         test_accum.add(1)
   ...         yield a,
   ...
   >>> df = TestUDTF(lit(10))
   >>> df.printSchema()
   root
    |-- col1: integer (nullable = true)
   
   >>> df.show()
   +----+
   |col1|
   +----+
   |  10|
   +----+
   
   >>> test_accum.value
   2
   ```
   
   or
   
   ```py
   >>> pyfile_path = "my_pyfile.py"
   >>> with open(pyfile_path, "w") as f:
   ...     f.write("my_func = lambda: 'col1'")
   ...
   24
   >>> sc.addPyFile(pyfile_path)
   >>> # or spark.addArtifacts(pyfile_path, pyfile=True)
   >>>
   >>> @udtf
   ... class TestUDTF:
   ...     @staticmethod
   ...     def analyze(a: AnalyzeArgument) -> AnalyzeResult:
   ...         import my_pyfile
   ...         return AnalyzeResult(StructType().add(my_pyfile.my_func(), 
a.data_type))
   ...     def eval(self, a):
   ...         yield a,
   ...
   >>> df = TestUDTF(lit(10))
   >>> df.printSchema()
   root
    |-- col1: integer (nullable = true)
   
   >>> df.show()
   +----+
   |col1|
   +----+
   |  10|
   +----+
   ```
   
   ### Why are the changes needed?
   
   To support missing features: `accumulator`, `broadcast`, and Spark files in 
Python UDTF's analyze.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, accumulator, broadcast in vanilla PySpark, and Spark files in both 
vanilla PySpark and Spark Connect Python client will be available.
   
   ### How was this patch tested?
   
   Added related tests.


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