dtenedor opened a new pull request, #60736:
URL: https://github.com/apache/spark/pull/60736

   ### What changes were proposed in this pull request?
   
   The Spark Connect Scala client rebuilds a server `ParseException` in 
`GrpcExceptionConverter.errorFactory` by rendering its message again from the 
client's own bundled `error-conditions.json`. When that file does not define 
the server's condition or subcondition, rendering throws 
`SparkException.internalError`, and that `INTERNAL_ERROR` replaces the server's 
error.
   
   This PR keeps the server's error in that case:
   
   - `GrpcExceptionConverter`: if `SparkThrowableHelper.isValidErrorClass` 
reports that the client's definitions lack the condition, build the 
`ParseException` from the message the server rendered, keeping the server's 
condition, message parameters, SQLSTATE and query context. When the condition 
is defined, the exception is built as before.
   - `ParseException`: a new `private[sql]` factory, 
`ParseException.withRenderedMessage`, creates an exception whose `getMessage` 
returns the server-rendered message unchanged (that message already includes 
the query context summary, so it is not appended again) and whose `getSqlState` 
returns the server's SQLSTATE. The private primary constructor gains the 
`sqlState` and `isMessageRendered` parameters it needs. The public constructors 
are unchanged.
   
   The decision is made per error from the client's own definitions, not by 
comparing client and server versions.
   
   ### Why are the changes needed?
   
   The client and server can run different Spark versions, and error conditions 
change between versions. SPARK-61835 renames the parser's 
`_LEGACY_ERROR_TEMP_*` conditions in batches (the first is #60588), so each 
batch adds names that older clients lack and removes legacy names that older 
servers still raise. Today, in both directions, such a statement still fails, 
but with `INTERNAL_ERROR` (SQLSTATE XX000) and a message saying the user hit a 
bug in Spark, for example:
   
   - a client without a new condition: `Error class 'INVALID_SQL_SYNTAX' has no 
'SET_TIME_ZONE_INVALID_VALUE' subclass.`
   - a client without a removed condition: `Cannot find main error class 
'_LEGACY_ERROR_TEMP_0045'`
   
   Code that catches `ParseException` or checks the condition or SQLSTATE stops 
matching. The same already happens for conditions removed by earlier renames. 
PySpark Connect keeps the server's message and is not affected.
   
   This was raised in the review of #60588.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, for a Spark Connect Scala client talking to a server whose parse error 
condition the client does not define. The client now throws a `ParseException` 
with the server's condition, SQLSTATE, message parameters, query context and 
message, instead of `SparkException` with `INTERNAL_ERROR`. Nothing changes 
when the client defines the condition.
   
   ### How was this patch tested?
   
   New tests in `SparkConnectClientSuite`:
   
   - A server `ParseException` whose subcondition the client lacks (with a 
query context and the server's SQLSTATE), and one whose main condition the 
client lacks (with no query context or SQLSTATE, as when only the truncated 
error status is available). Each keeps the server's condition, SQLSTATE, 
message parameters and query context, and `getMessage` returns the server 
message exactly once. Without the converter change, this test fails with 
`[INTERNAL_ERROR] Error class 'INVALID_SQL_SYNTAX' has no 
'SUBCONDITION_NOT_DEFINED_BY_CLIENT' subclass.`
   - A server `ParseException` whose condition the client defines is still 
rendered from the client's definitions.
   
   `SparkConnectClientSuite`, `ErrorParserSuite` and `ParserUtilsSuite` pass, 
and scalastyle and scalafmt are clean.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to