HyukjinKwon commented on code in PR #45377:
URL: https://github.com/apache/spark/pull/45377#discussion_r1549232872


##########
python/pyspark/errors/utils.py:
##########
@@ -119,3 +124,61 @@ def get_message_template(self, error_class: str) -> str:
             message_template = main_message_template + " " + 
sub_message_template
 
         return message_template
+
+
+def _capture_call_site(fragment: 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()

Review Comment:
   I think we should probably just `getActiveSession`, and skip if it returns 
`None` for whatever reason instead of creating a new session here.



##########
python/pyspark/errors/utils.py:
##########
@@ -119,3 +124,61 @@ def get_message_template(self, error_class: str) -> str:
             message_template = main_message_template + " " + 
sub_message_template
 
         return message_template
+
+
+def _capture_call_site(fragment: 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

Review Comment:
   Import on the top maybe



-- 
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-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to