itholic commented on code in PR #39591:
URL: https://github.com/apache/spark/pull/39591#discussion_r1073012053
##########
python/pyspark/errors/exceptions.py:
##########
@@ -69,8 +75,248 @@ def getMessageParameters(self) -> Optional[Dict[str, str]]:
See Also
--------
:meth:`PySparkException.getErrorClass`
+ :meth:`PySparkException.getSqlState`
"""
return self.message_parameters
+ def getSqlState(self) -> None:
+ """
+ Returns an SQLSTATE as a string.
+
+ Errors generated in Python have no SQLSTATE, so it always returns None.
+
+ .. versionadded:: 3.4.0
+
+ See Also
+ --------
+ :meth:`PySparkException.getErrorClass`
+ :meth:`PySparkException.getMessageParameters`
+ """
+ return None
+
def __str__(self) -> str:
return f"[{self.getErrorClass()}] {self.message}"
+
+
+class CapturedException(PySparkException):
+ def __init__(
+ self,
+ desc: Optional[str] = None,
+ stackTrace: Optional[str] = None,
+ cause: Optional[Py4JJavaError] = None,
+ origin: Optional[Py4JJavaError] = None,
+ ):
+ # desc & stackTrace vs origin are mutually exclusive.
+ # cause is optional.
+ assert (origin is not None and desc is None and stackTrace is None) or
(
+ origin is None and desc is not None and stackTrace is not None
+ )
+
+ self.desc = desc if desc is not None else cast(Py4JJavaError,
origin).getMessage()
+ assert SparkContext._jvm is not None
+ self.stackTrace = (
+ stackTrace
+ if stackTrace is not None
+ else
(SparkContext._jvm.org.apache.spark.util.Utils.exceptionString(origin))
+ )
+ self.cause = convert_exception(cause) if cause is not None else None
+ if self.cause is None and origin is not None and origin.getCause() is
not None:
+ self.cause = convert_exception(origin.getCause())
+ self._origin = origin
+
+ def __str__(self) -> str:
+ assert SparkContext._jvm is not None
+
+ jvm = SparkContext._jvm
+ sql_conf = jvm.org.apache.spark.sql.internal.SQLConf.get()
+ debug_enabled = sql_conf.pysparkJVMStacktraceEnabled()
+ desc = self.desc
+ if debug_enabled:
+ desc = desc + "\n\nJVM stacktrace:\n%s" % self.stackTrace
+ return str(desc)
+
+ def getErrorClass(self) -> Optional[str]:
+ """
+ Returns an error class as a string.
+
+ .. versionadded:: 3.4.0
+
+ See Also
+ --------
+ :meth:`CapturedException.getMessageParameters`
Review Comment:
I refer the `CapturedException.getMessageParameters` here, since it's
docstring for `CapturedException.getErrorClass `.
But on my second thought, maybe we should remove all docstrings from methods
in `CapturedException` since it's not an API ?
--
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]