spark-test commented on code in PR #60673:
URL: https://github.com/apache/spark/pull/60673#discussion_r4619229928
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCRDD.scala:
##########
@@ -72,6 +72,9 @@ object JDBCRDD extends Logging {
try {
getQueryOutputSchema(fullQuery, options, dialect, conn)
} catch {
+ // Must precede isObjectNotFoundException, whose default matches any
42xxx SQLSTATE.
+ case e: SQLException if dialect.isPermissionDeniedException(e) =>
Review Comment:
**Non-blocking (P2):** This case only covers the schema query. The catch
around the data query in `compute` (lines 366-372 of this file), which this PR
also rewrote, still checks only `isSyntaxErrorBestEffort`, and
`PostgresDialect` limits that check to 42601. So if PostgreSQL rejects the data
query with 42501 after schema resolution succeeded, the job still fails with
Spark's generic "Job aborted due to stage failure" error, which carries the raw
`PSQLException` and no error condition. Meanwhile the same denial during
`load()` now raises `JDBC_EXTERNAL_ENGINE_PERMISSION_ERROR`, so error handling
keyed on the new condition misses the query-execution case.
Reading the code, one way to reach it: a login that can read `t` loads it
with `.option("sessionInitStatement", "SET ROLE reporting")`, where `reporting`
cannot read `t`. `load()` succeeds, because schema resolution opens its own
connection and never runs the session statement. `collect()` then runs `SET
ROLE reporting` before the generated `SELECT`, which PostgreSQL rejects with
42501. In a classic session, revoking the privilege between `load()` and
`collect()` has the same effect.
Suggested fix: add a `dialect.isPermissionDeniedException(e)` case ahead of
the syntax case in `compute`, add a `DURING_QUERY_EXECUTION` subclass to
`JDBC_EXTERNAL_ENGINE_PERMISSION_ERROR` as the syntax-error condition has, and
give `jdbcExternalEnginePermissionError` the same `isSchemaResolution`
parameter as `jdbcExternalEngineSyntaxError`. If the data query is meant to
stay out of this PR, a TODO at the `compute` catch naming it would make the gap
visible to readers.
**Verification:**
- **Regression:** Cover a JDBC read whose dialect recognizes SQLSTATE 42501
as a permission failure, as the PostgreSQL dialect does, in which the schema
query succeeds and only the data query is rejected with SQLSTATE 42501 when it
is executed. Assert that collecting it fails with
JDBC_EXTERNAL_ENGINE_PERMISSION_ERROR.DURING_QUERY_EXECUTION and SQLSTATE
42501, with the generated data query, the driver's SQLSTATE and its message as
parameters, and the driver exception as cause.
- **Compatibility:** Cover the same data-query failure under a dialect that
does not override isPermissionDeniedException, such as H2, and assert that it
keeps its current query-execution classification rather than becoming a
permission error.
- **Inspection:** Check that the isPermissionDeniedException documentation
in JdbcDialects.scala describes Spark reporting the permission condition for
both the schema query and the data query, and that
JDBC_EXTERNAL_ENGINE_PERMISSION_ERROR defines both phase subclasses with the
same messages as JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR.
--
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]