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

   ### What changes were proposed in this pull request?
   
   Basic support of SparkSession based Python UDF profiler.
   
   To enable the profiler, use a SQL conf `spark.sql.pyspark.udf.profiler`:
   
   - `"perf"`: enable cProfiler
   - "memory": enable memory-profiler (TODO: 
[SPARK-46687](https://issues.apache.org/jira/browse/SPARK-46687))
   
   ```py
   from pyspark.sql.functions import *
   
   spark.conf.set("spark.sql.pyspark.udf.profiler", "perf")  # enable cProfiler
   
   @udf("string")
   def f(x):
         return str(x)
   
   df = spark.range(10).select(f(col("id")))
   df.collect()
   
   @pandas_udf("string")
   def g(x):
        return x.astype("string")
   
   df = spark.range(10).select(g(col("id")))
   
   spark.conf.unset("spark.sql.pyspark.udf.profiler")  # disable
   
   df.collect()  # won't profile
   
   spark.show_perf_profiles()  # show the result for only the first collect.
   ```
   
   ### Why are the changes needed?
   
   The existing UDF profilers are SparkContext based, which can't support Spark 
Connect.
   
   We should introduce SparkSession based profilers and support Spark Connect.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, SparkSession-based UDF profilers will be available.
   
   ### How was this patch tested?
   
   Added the related tests, manually, and existing tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.
   


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