milos-stojanovic-db opened a new pull request, #59297:
URL: https://github.com/apache/spark/pull/59297

   ### What changes were proposed in this pull request?
   
   Spark classifies JDBC output-schema-resolution failures in 
`JDBCRDD.resolveTable`
   via dialect hooks (`isObjectNotFoundException`, `isSyntaxErrorBestEffort`),
   throwing `JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR`. This PR adds the same 
treatment for
   permission denials:
   
   - New `JdbcDialect.isInsufficientPrivilegeException(e: SQLException): 
Boolean`
     (default `false`).
   - `JDBCRDD.resolveTable` checks it **first** (before object-not-found and
     syntax-error) and throws a new error condition
     `JDBC_EXTERNAL_ENGINE_INSUFFICIENT_PRIVILEGE` (SQLSTATE `42501`) that 
includes
     the pushed-down query, the remote SQLSTATE, and the remote message.
   - `AggregatedDialect` matches if **any** delegate recognizes the error (note:
     this differs from `isSyntaxErrorBestEffort`, which only consults
     `dialects.head`; using `exists` here means a user-registered dialect that 
does
     not override the hook can't suppress built-in detection).
   - Per-dialect detection for PostgreSQL, MySQL/MariaDB, SQL Server, Oracle,
     Snowflake, Teradata, DB2 and Databricks (see the JIRA for the code table).
     Oracle `ORA-00942` and Snowflake `2003` are ambiguous and intentionally 
stay
     object-not-found.
   
   ### Why are the changes needed?
   
   A remote permission denial during schema resolution has no classification of
   its own. Dialects that treat class-42 / `42000` SQLSTATEs as syntax errors
   (MySQL, Oracle, Snowflake, Teradata, DB2, Databricks) report it as
   `JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR`, and PostgreSQL has propagated `42501` 
as an
   unclassified driver error since SPARK-59336. Either way, callers can't tell
   "insufficient privileges" apart from "malformed SQL". A dedicated error class
   with SQLSTATE `42501` lets tools and users react to it.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A JDBC read that fails during output-schema resolution because of a 
remote
   permission denial now raises `JDBC_EXTERNAL_ENGINE_INSUFFICIENT_PRIVILEGE`
   (SQLSTATE `42501`) instead of `JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR` / an
   unclassified exception. This affects only error classification; successful 
reads
   are unchanged.
   
   ### How was this patch tested?
   
   New unit tests in `JDBCSuite`:
   - Per-dialect classification (positive + negative cases for each dialect).
   - End-to-end: a registered test dialect over H2 makes `spark.read.jdbc` raise
     `JDBC_EXTERNAL_ENGINE_INSUFFICIENT_PRIVILEGE` with SQLSTATE `42501`.
   - A custom PostgreSQL dialect that does not override the hook still gets
     built-in detection via `AggregatedDialect`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus)
   


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