You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ueshin (via GitHub)" <gi...@apache.org> on 2023/02/09 23:41:18 UTC
[GitHub] [spark] ueshin commented on a diff in pull request #39947: [SPARK-40453][SPARK-41715][CONNECT] Take super class into account when throwing an exception
ueshin commented on code in PR #39947:
URL: https://github.com/apache/spark/pull/39947#discussion_r1102122698
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectService.scala:
##########
@@ -83,39 +106,35 @@ class SparkConnectService(debug: Boolean)
private def handleError[V](
opType: String,
observer: StreamObserver[V]): PartialFunction[Throwable, Unit] = {
- case ae: AnalysisException =>
- logError(s"Error during: $opType", ae)
- val status = RPCStatus
- .newBuilder()
- .setCode(RPCCode.INTERNAL_VALUE)
- .addDetails(
- ProtoAny.pack(
- ErrorInfo
- .newBuilder()
- .setReason(ae.getClass.getName)
- .setDomain("org.apache.spark")
- .putMetadata("message", ae.getSimpleMessage)
- .putMetadata("plan", Option(ae.plan).flatten.map(p => s"$p").getOrElse(""))
- .build()))
- .setMessage(ae.getLocalizedMessage)
- .build()
- observer.onError(StatusProto.toStatusRuntimeException(status))
+ case se: SparkException
+ if se.getCause != null && se.getCause
+ .isInstanceOf[PythonException] && se.getCause.getStackTrace
+ .exists(_.toString.contains("org.apache.spark.sql.execution.python")) =>
+ // Python UDF execution
Review Comment:
I guess we should extract this part to a method with a proper name for readability?
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectService.scala:
##########
@@ -83,39 +106,35 @@ class SparkConnectService(debug: Boolean)
private def handleError[V](
opType: String,
observer: StreamObserver[V]): PartialFunction[Throwable, Unit] = {
- case ae: AnalysisException =>
- logError(s"Error during: $opType", ae)
- val status = RPCStatus
- .newBuilder()
- .setCode(RPCCode.INTERNAL_VALUE)
- .addDetails(
- ProtoAny.pack(
- ErrorInfo
- .newBuilder()
- .setReason(ae.getClass.getName)
- .setDomain("org.apache.spark")
- .putMetadata("message", ae.getSimpleMessage)
- .putMetadata("plan", Option(ae.plan).flatten.map(p => s"$p").getOrElse(""))
- .build()))
- .setMessage(ae.getLocalizedMessage)
- .build()
- observer.onError(StatusProto.toStatusRuntimeException(status))
+ case se: SparkException
+ if se.getCause != null && se.getCause
+ .isInstanceOf[PythonException] && se.getCause.getStackTrace
+ .exists(_.toString.contains("org.apache.spark.sql.execution.python")) =>
+ // Python UDF execution
+ logError(s"Error during: $opType", se)
+ observer.onError(
+ StatusProto.toStatusRuntimeException(buildStatusFromThrowable(se.getCause)))
+
case st: SparkThrowable =>
logError(s"Error during: $opType", st)
- val status = buildStatusFromThrowable(st)
- observer.onError(StatusProto.toStatusRuntimeException(status))
+ observer.onError(StatusProto.toStatusRuntimeException(buildStatusFromThrowable(st)))
+
case NonFatal(nf) =>
logError(s"Error during: $opType", nf)
val status = RPCStatus
.newBuilder()
.setCode(RPCCode.INTERNAL_VALUE)
- .setMessage(nf.getLocalizedMessage)
+ .setMessage(StringUtils.abbreviate(nf.getMessage, 2048))
.build()
observer.onError(StatusProto.toStatusRuntimeException(status))
Review Comment:
Need to add the details: #39957.
##########
python/pyspark/errors/exceptions/connect.py:
##########
@@ -61,41 +97,34 @@ class AnalysisException(SparkConnectGrpcException, BaseAnalysisException):
Failed to analyze a SQL query plan from Spark Connect server.
"""
- def __init__(
- self,
- message: Optional[str] = None,
- error_class: Optional[str] = None,
- message_parameters: Optional[Dict[str, str]] = None,
- plan: Optional[str] = None,
- reason: Optional[str] = None,
- ) -> None:
- self.message = message # type: ignore[assignment]
- if plan is not None:
- self.message = f"{self.message}\nPlan: {plan}"
Review Comment:
What's the captured one's stack trace like?
--
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