Commit f548c8a
[SPARK-57778][SQL] Handle Oracle JDBC objects that are not selectable 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, for example 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 are currently unclassified, so `tableExists` throws instead of returning `false`, and table resolution surfaces a raw `FAILED_JDBC` error.
This PR adds a new `JdbcDialect.isNotSelectableObjectException` predicate (default `false`; `OracleDialect` recognizes `ORA-04044`/`ORA-04063`), kept separate from `isObjectNotFoundException` ("object does not exist"). With it:
- `JdbcUtils.tableExists` returns `false` for such objects instead of throwing;
- `JDBCRDD.resolveTable` throws a dedicated, clear error condition `JDBC_OBJECT_NOT_SELECTABLE` instead 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:
- reading an object that is not selectable as a table now fails with the dedicated error condition `JDBC_OBJECT_NOT_SELECTABLE` (SQLSTATE `42000`) instead of a raw `FAILED_JDBC` error;
- `tableExists` returns `false` for 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 (both `ORA-04044`), and an invalid view (`ORA-04063`). Each asserts that `tableExists` returns `false` and that reading the object fails with `JDBC_OBJECT_NOT_SELECTABLE`.
### Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored using Cursor (AI assistant).
Closes #56898 from ivan-leventsov/oracle-skip-non-selectable-objects.
Authored-by: ivan-leventsov <ivan.leventsov@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 48f1211)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent b71d60d commit f548c8a
7 files changed
Lines changed: 96 additions & 1 deletion
File tree
- common/utils/src/main/resources/error
- connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2
- sql
- catalyst/src/main/scala/org/apache/spark/sql/errors
- core/src/main/scala/org/apache/spark/sql
- execution/datasources/jdbc
- jdbc
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5309 | 5309 | | |
5310 | 5310 | | |
5311 | 5311 | | |
| 5312 | + | |
| 5313 | + | |
| 5314 | + | |
| 5315 | + | |
| 5316 | + | |
| 5317 | + | |
5312 | 5318 | | |
5313 | 5319 | | |
5314 | 5320 | | |
| |||
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
206 | 263 | | |
207 | 264 | | |
208 | 265 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1703 | 1703 | | |
1704 | 1704 | | |
1705 | 1705 | | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
1706 | 1717 | | |
1707 | 1718 | | |
1708 | 1719 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
808 | 808 | | |
809 | 809 | | |
810 | 810 | | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
811 | 820 | | |
812 | 821 | | |
813 | 822 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
57 | 64 | | |
58 | 65 | | |
59 | 66 | | |
| |||
0 commit comments