You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "itholic (via GitHub)" <gi...@apache.org> on 2024/04/02 13:01:44 UTC
Re: [PR] [SPARK-47274][PYTHON][SQL] Provide more useful context for PySpark DataFrame API errors [spark]
itholic commented on code in PR #45377:
URL: https://github.com/apache/spark/pull/45377#discussion_r1547836649
##########
python/pyspark/errors/utils.py:
##########
@@ -119,3 +124,62 @@ def get_message_template(self, error_class: str) -> str:
message_template = main_message_template + " " + sub_message_template
return message_template
+
+
+def _capture_call_site(func_name: str) -> None:
+ """
+ Capture the call site information including file name, line number, and function name.
+
+ This function updates the thread-local storage from server side (PySparkCurrentOrigin)
+ with the current call site information when a PySpark API function is called.
+
+ Parameters
+ ----------
+ func_name : str
+ The name of the PySpark API function being captured.
+
+ Notes
+ -----
+ The call site information is used to enhance error messages with the exact location
+ in the user code that led to the error.
+ """
+ from pyspark.sql.session import SparkSession
+
+ spark = SparkSession._getActiveSessionOrCreate()
+ assert spark._jvm is not None
+
+ stack = inspect.stack()
+ frame_info = stack[-1]
+ function = func_name
+ filename = frame_info.filename
+ lineno = frame_info.lineno
+ call_site = f'"{function}" was called from\n{filename}:{lineno}'
Review Comment:
Let me extract `fragment` from PySpark function name for consistency.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org