-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-50858][PYTHON] Add configuration to hide Python UDF stack trace
### What changes were proposed in this pull request? This PR adds new configuration `spark.sql.execution.pyspark.udf.hideTraceback.enabled`. If set, when handling an exception from Python UDF, only the exception class and message are included. The configuration is turned off by default. This PR also adds a new optional parameter `hide_traceback` for `handle_udf_exception` to override the configuration. Suggested review order: 1. `python/pyspark/util.py`: logic changes 2. `python/pyspark/tests/test_util.py`: unit tests 3. other files: adding new configuration ### Why are the changes needed? This allows library provided UDFs to show only the relevant message without unnecessary stack trace. ### Does this PR introduce _any_ user-facing change? If the configuration is turned off, no user change. Otherwise, the stack trace is not included in the error message when handling an exception from Python UDF. <details> <summary>Example that illustrates the difference</summary> ```py from pyspark.errors.exceptions.base import PySparkRuntimeError from pyspark.sql.types import IntegerType, StructField, StructType from pyspark.sql.udtf import AnalyzeArgument, AnalyzeResult from pyspark.sql.functions import udtf udtf() class PythonUDTF: staticmethod def analyze(x: AnalyzeArgument) -> AnalyzeResult: raise PySparkRuntimeError("[XXX] My PySpark runtime error.") def eval(self, x: int): yield (x,) spark.udtf.register("my_udtf", PythonUDTF) spark.sql("select * from my_udtf(1)").show() ``` With configuration turned off, the last line gives: ``` ... pyspark.errors.exceptions.captured.AnalysisException: [TABLE_VALUED_FUNCTION_FAILED_TO_ANALYZE_IN_PYTHON] Failed to analyze the Python user defined table function: Traceback (most recent call last): File "<stdin>", line 7, in analyze pyspark.errors.exceptions.base.PySparkRuntimeError: [XXX] My PySpark runtime error. SQLSTATE: 38000; line 1 pos 14 ``` With configuration turned on, the last line gives: ``` ... pyspark.errors.exceptions.captured.AnalysisException: [TABLE_VALUED_FUNCTION_FAILED_TO_ANALYZE_IN_PYTHON] Failed to analyze the Python user defined table function: pyspark.errors.exceptions.base.PySparkRuntimeError: [XXX] My PySpark runtime error. SQLSTATE: 38000; line 1 pos 14 ``` </details> ### How was this patch tested? Added unit test in `python/pyspark/tests/test_util.py`, testing two cases with the configuration turned on and off respectively. ### Was this patch authored or co-authored using generative AI tooling? No Closes #49535 from wengh/spark-50858-hide-udf-stack-trace. Authored-by: Haoyu Weng <[email protected]> Signed-off-by: Allison Wang <[email protected]> (cherry picked from commit d259132) Signed-off-by: Allison Wang <[email protected]>
- Loading branch information
1 parent
83d5d44
commit 40f6b3f
Showing
11 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters