[SPARK-57778][SQL] Handle Oracle JDBC objects that are not selectable as tables#56898
Open
ivan-leventsov wants to merge 1 commit into
Open
[SPARK-57778][SQL] Handle Oracle JDBC objects that are not selectable as tables#56898ivan-leventsov wants to merge 1 commit into
ivan-leventsov wants to merge 1 commit into
Conversation
30f2dac to
54139ed
Compare
MaxGekk
reviewed
Jun 30, 2026
MaxGekk
left a comment
Member
There was a problem hiding this comment.
0 blocking, 1 non-blocking, 0 nits.
Clean Oracle error-classification extension that faithfully mirrors the existing isObjectNotFoundException predicate pattern (dialect default + Oracle override + tableExists/resolveTable wiring), kept deliberately separate so "not found" and "not selectable" stay distinct conditions.
Suggestions (1)
JdbcDialects.scala:811:@Since("4.2.0")looks stale — currentbranch-4.xis4.3.0, so a method added now first ships there — see inline.
Verification
- Predicate disjointness (the key correctness point):
OracleDialectoverridesisObjectNotFoundExceptionto match onlyORA-00942/ORA-39165, so it does NOT interceptORA-04044/ORA-04063. The newisNotSelectableObjectExceptionbranch inresolveTableis therefore reachable (not dead), and it precedes theisSyntaxErrorBestEffort(42000) case so a 42000 SQLState can't divert it.tableExistsreturnsfalsefor these objects. - Default
falseleaves non-Oracle dialects unaffected; the error condition is alphabetically placed with a matching<objectName>param and chained cause. Integration tests cover ORA-04044 (procedure + broken-function synonyms) and ORA-04063 (invalid view), asserting bothtableExists=falseand the dedicated error.
| Option(e.getSQLState).exists(_.startsWith("42")) | ||
| } | ||
|
|
||
| @Since("4.2.0") |
Member
There was a problem hiding this comment.
dev/next_version_candidates.py reports the current branch-4.x at 4.3.0 (master 5.0.0), so a method added now first ships in 4.3.0 — 4.2.0 looks like it predates the recent version bump (the existing @Since("4.2.0") entries in this file are from the prior cycle).
Suggested change
| @Since("4.2.0") | |
| @Since("4.3.0") |
… as tables
### What changes were proposed in this pull request?
When using the built-in JDBC `TableCatalog` over Oracle, the driver's table listing
returns objects that cannot be read as tables, e.g. a synonym that resolves to a PL/SQL
procedure/function/package, or an invalid view. Probing such an object (`tableExists` via
`SELECT 1 FROM <obj> WHERE 1=0`, or schema resolution via `SELECT * FROM <obj> WHERE 1=0`)
raises `ORA-04044` ("procedure, function, package, or type is not allowed here") or
`ORA-04063` ("... has errors"). These were unclassified, so `tableExists` threw and table
resolution surfaced a raw `FAILED_JDBC` failure.
This adds a `JdbcDialect.isNotSelectableObjectException` predicate (Oracle recognizes
`ORA-04044`/`ORA-04063`) so:
- `JdbcUtils.tableExists` returns `false` for such objects instead of throwing;
- `JDBCRDD.resolveTable` throws a dedicated, clear error (`JDBC_OBJECT_NOT_SELECTABLE`)
instead of a generic failure.
### Why are the changes needed?
A schema legitimately contains synonyms/views that are not selectable tables; probing them
should not surface a raw external-engine error or make existence checks throw.
### Does this PR introduce any user-facing change?
Yes. Querying such an object now returns `JDBC_OBJECT_NOT_SELECTABLE` instead of a raw
`FAILED_JDBC` error, and `tableExists` returns `false` for it.
### How was this patch tested?
New cases in `OracleIntegrationSuite` (docker-integration-tests): synonym to a procedure,
synonym to a broken function, and an invalid view.
54139ed to
be95c45
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
When using the built-in JDBC
TableCatalogover Oracle, the driver's table listing returns objects that cannot be read as tables, for example a synonym that resolves to a PL/SQL procedure/function/package, or an invalid view. Probing such an object (tableExistsviaSELECT 1 FROM <obj> WHERE 1=0, or schema resolution viaSELECT * FROM <obj> WHERE 1=0) raisesORA-04044("procedure, function, package, or type is not allowed here") orORA-04063("... has errors"). These are currently unclassified, sotableExiststhrows instead of returningfalse, and table resolution surfaces a rawFAILED_JDBCerror.This PR adds a new
JdbcDialect.isNotSelectableObjectExceptionpredicate (defaultfalse;OracleDialectrecognizesORA-04044/ORA-04063), kept separate fromisObjectNotFoundException("object does not exist"). With it:JdbcUtils.tableExistsreturnsfalsefor such objects instead of throwing;JDBCRDD.resolveTablethrows a dedicated, clear error conditionJDBC_OBJECT_NOT_SELECTABLEinstead of a generic failure.Why are the changes needed?
A schema legitimately contains synonyms/views that are not selectable as tables. Probing them should not surface a raw external-engine error or make existence checks throw; such objects should be reported as not a readable table.
Does this PR introduce any user-facing change?
Yes. For a JDBC catalog over Oracle:
JDBC_OBJECT_NOT_SELECTABLE(SQLSTATE42000) instead of a rawFAILED_JDBCerror;tableExistsreturnsfalsefor such an object instead of throwing.How was this patch tested?
New cases in
org.apache.spark.sql.jdbc.v2.OracleIntegrationSuite(docker-integration-tests), covering a synonym to a procedure, a synonym to a broken function (bothORA-04044), and an invalid view (ORA-04063). Each asserts thattableExistsreturnsfalseand that reading the object fails withJDBC_OBJECT_NOT_SELECTABLE.Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored using Cursor (AI assistant).