spark-test commented on code in PR #60736:
URL: https://github.com/apache/spark/pull/60736#discussion_r4655463793
##########
sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/client/SparkConnectClientSuite.scala:
##########
@@ -393,6 +396,131 @@ class SparkConnectClientSuite extends ConnectFunSuite {
}
}
+ // The errorFactory entries that rebuild a server error from this client's
error definitions.
+ // StreamingQueryException and SparkException always keep the server's
message.
+ private val renderingErrorFactory =
GrpcExceptionConverter.errorFactory.filter {
+ case (name, _) =>
+ name != classOf[StreamingQueryException].getName && name !=
classOf[SparkException].getName
+ }
+
+ private def isInstanceOf(error: Throwable, className: String): Boolean =
+ Iterator
+ .iterate[Class[_]](error.getClass)(_.getSuperclass)
+ .takeWhile(_ != null)
+ .exists(_.getName == className)
+
+ // Entries whose exception type carries no query context.
+ private val withoutQueryContext = Set(
+ classOf[NamespaceAlreadyExistsException],
+ classOf[TableAlreadyExistsException],
+ classOf[TempTableAlreadyExistsException],
+ classOf[NoSuchDatabaseException],
+ classOf[NoSuchNamespaceException],
+ classOf[NoSuchTableException],
+ classOf[UnsupportedOperationException],
+ classOf[SparkUpgradeException]).map(_.getName)
+
+ // Entries whose exception type keeps the cause rebuilt from the server's
error chain.
Review Comment:
**Nit (P3):** This comment gives the exception type as the reason an entry
belongs in `withCause`, which, by the review's reading of the code, is false
for two of the excluded entries. `SparkDateTimeException` extends
`DateTimeException(message, cause.orNull)` (`SparkException.scala` line 444),
and the new `SparkDateTimeException.withRenderedMessage`
(`SparkException.scala` lines 423-431) and
`NoSuchNamespaceException.withRenderedMessage` (`noSuchItemsExceptions.scala`
lines 92-98) both take a cause and pass it on. The `DateTimeException` and
`NoSuchNamespaceException` entries return no cause because the converter passes
`cause = None` in both of their branches (`GrpcExceptionConverter.scala` lines
424, 529 and 536; the two-argument `NoSuchNamespaceException` constructor takes
none), as the base branch's rendering already did.
So the set itself is right: it lists the entries that keep the cause when
the client renders the error, and each entry handles the cause the same way
when the client cannot. Only the stated reason is wrong. Because this comment
is the only place in the change that explains the split, a maintainer who later
revisits those `cause = None` arguments would start from the false premise that
the two types cannot carry a cause. Rewording the comment is enough; the set
and the assertions stay as they are:
```suggestion
// Entries that keep the cause rebuilt from the server's error chain when
the client renders the
// error. Each entry handles the cause the same way when the client cannot
render the error, so
// the DateTimeException and NoSuchNamespaceException entries drop it in
both cases, although
// their exception types can carry a cause.
```
This extends an [existing
discussion](https://github.com/apache/spark/pull/60736#discussion_r4647163047).
**Verification:**
- **Inspection:** The comment above the withCause set in
SparkConnectClientSuite.scala says that the set lists the converter entries
that keep the cause rebuilt from the server's error chain when the client
renders the error, and that each entry handles the cause the same way when the
client cannot render it. It no longer says that the exception type decides
membership, which is false for the DateTimeException and
NoSuchNamespaceException entries because both exception types can carry a cause.
--
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]