ueshin commented on code in PR #52755:
URL: https://github.com/apache/spark/pull/52755#discussion_r2470634328
##########
python/pyspark/errors/exceptions/captured.py:
##########
@@ -118,68 +118,45 @@ def getErrorClass(self) -> Optional[str]:
def getMessageParameters(self) -> Optional[Dict[str, str]]:
from pyspark import SparkContext
from py4j.java_gateway import is_instance_of
- from py4j.protocol import Py4JError
assert SparkContext._gateway is not None
gw = SparkContext._gateway
if self._origin is not None and is_instance_of(
gw, self._origin, "org.apache.spark.SparkThrowable"
):
- try:
- return dict(self._origin.getMessageParameters())
- except Py4JError as e:
- if "py4j.Py4JException" in str(e) and "Method
getMessageParameters" in str(e):
- return None
- raise e
+ return
dict(SparkContext._jvm.PythonErrorUtils.getMessageParameters(self._origin))
else:
return None
def getSqlState(self) -> Optional[str]:
from pyspark import SparkContext
from py4j.java_gateway import is_instance_of
- from py4j.protocol import Py4JError
assert SparkContext._gateway is not None
gw = SparkContext._gateway
if self._origin is not None and is_instance_of(
gw, self._origin, "org.apache.spark.SparkThrowable"
):
- try:
- return self._origin.getSqlState()
- except Py4JError as e:
- if "py4j.Py4JException" in str(e) and "Method getSqlState" in
str(e):
- return None
- raise e
+ return
dict(SparkContext._jvm.PythonErrorUtils.getSqlState(self._origin))
Review Comment:
`dict` is not necessary?
##########
core/src/main/scala/org/apache/spark/api/python/PythonErrorUtils.scala:
##########
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.api.python
+
+import java.util
+
+import org.apache.spark.{BreakingChangeInfo, QueryContext, SparkThrowable}
+
+/**
+ * Utility object that provides convenient accessors for extracting
+ * detailed information from a [[SparkThrowable]] instance.
+ *
+ * This object is primarily used in PySpark
+ * to retrieve structured error metadata because Py4J does not work
+ * with default methods.
+ */
+private[spark] object PythonErrorUtils {
+ def getErrorClass(e: SparkThrowable): String = e.getCondition
Review Comment:
It should have `getCondition`? And `getErrorClass` should call
`e.getErrorClass`.
##########
core/src/test/scala/org/apache/spark/deploy/PythonRunnerSuite.scala:
##########
@@ -64,4 +65,31 @@ class PythonRunnerSuite extends SparkFunSuite {
intercept[IllegalArgumentException] {
PythonRunner.formatPaths("hdfs:/some.py,foo.py") }
intercept[IllegalArgumentException] {
PythonRunner.formatPaths("foo.py,hdfs:/some.py") }
}
+
+ test("PythonErrorUtils should have corresponding methods for default methods
in SparkThrowable") {
+ // Find default methods in SparkThrowable
+ val defaultMethods = classOf[SparkThrowable]
+ .getMethods
+ .filter(m => m.getDeclaringClass == classOf[SparkThrowable] &&
m.isDefault)
Review Comment:
We don't need to filter with the default method here? We can always call
methods through `PythonErrorUtils` and it should have the same methods as
`SparkThrowable`?
--
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]