Commit addeeb7
authored
Resolve null catalog/schema in SEA key-based metadata operations (#1370)
## Summary
- Adds null-resolution logic for SEA key-based metadata operations
(`getPrimaryKeys`, `getImportedKeys`, `getCrossReference`) to match
Thrift server behavior
- Adds `getCurrentCatalogAndSchema()` to `IDatabricksSession` — fetches
both current catalog and schema in a single `SELECT CURRENT_CATALOG(),
CURRENT_SCHEMA()` query
- Refactors `getCurrentCatalog()` to delegate to
`getCurrentCatalogAndSchema()[0]`, eliminating duplicate query logic
- Adds `resolveKeyBasedParams()` as a shared helper in
`DatabricksMetadataQueryClient` for consistent null-replacement across
all key-based operations
- Adds 15 integration tests with WireMock record/replay stubs
## Problem
SEA metadata operations build SQL commands like `SHOW KEYS IN CATALOG x
IN SCHEMA y IN TABLE z` which require explicit values. When users pass
`null` for catalog/schema (standard JDBC behavior), SEA previously
returned empty results or threw errors — unlike Thrift where the server
resolves nulls to current catalog/schema.
## Null Resolution Rules (matching Thrift server behavior)
Verified via live Thrift testing against Databricks workspace:
| Parameter | Rule |
|---|---|
| `catalog=null` | Replace with `CURRENT_CATALOG()` |
| `schema=null` + catalog was also null | Replace with
`CURRENT_SCHEMA()` |
| `schema=null` + catalog explicitly provided | Return empty result |
| `table=null` | Return empty result |
The key invariant: **schema is only auto-filled when catalog is also
null**. If catalog is explicitly provided (even if it matches the
current catalog), null schema returns empty — matching Thrift server
behavior exactly.
## Thrift Behavior Evidence
With current catalog=`main`, current schema=`msr_testing`:
**getPrimaryKeys:**
- `(null, null, 'test_parent')` → **1 row found** (resolved to current
catalog+schema)
- `(null, 'msr_testing', 'test_parent')` → **1 row found** (null catalog
resolved, explicit schema used)
- `('main', null, 'test_parent')` → **EXCEPTION** (explicit catalog +
null schema)
- `('main', 'msr_testing', 'test_parent')` → **1 row found** (fully
specified)
**getCrossReference:**
- `(null, null, test_parent, null, null, test_child)` → **1 row** (both
sides resolved)
- `(null, msr_testing, test_parent, null, msr_testing, test_child)` →
**1 row**
- `(main, null, test_parent, main, msr_testing, test_child)` →
**EXCEPTION** (explicit catalog + null schema)
## Files Changed
| File | Change |
|---|---|
| `IDatabricksSession.java` | Added `getCurrentCatalogAndSchema()`
interface method |
| `DatabricksSession.java` | Implemented `getCurrentCatalogAndSchema()`,
refactored `getCurrentCatalog()` to delegate |
| `DatabricksMetadataQueryClient.java` | Added
`resolveKeyBasedParams()`, updated `listPrimaryKeys`,
`listImportedKeys`, `listCrossReferences` |
| `DatabricksMetadataQueryClientTest.java` | Added
`testKeyBasedOpsReturnEmptyForNullTable`,
`testKeyBasedOpsReturnEmptyForNullSchemaWithExplicitCatalog`, removed
stale stubs |
| `MetadataNullResolutionTests.java` | New: 15 integration tests with
WireMock stubs for all null-resolution scenarios |
## Not Changed
- **Thrift implementation** — server handles nulls, no client changes
needed
- **Pattern-based operations** (getSchemas, getTables, getColumns,
getFunctions) — these use LIKE patterns, not exact keys
- **listExportedKeys** — already returns empty (not supported in DBSQL)
- **CommandBuilder** — receives resolved non-null values
## Test plan
- [x] Unit tests pass: `DatabricksMetadataQueryClientTest` (52 tests)
- [x] Unit tests pass: `DatabricksDatabaseMetaDataTest` (248 tests)
- [x] Integration tests pass: `MetadataNullResolutionTests` (15 tests,
REPLAY mode)
- [x] Integration tests recorded and verified against e2-dogfood staging
(RECORD mode)
- [x] Live verification against Databricks workspace with Thrift to
confirm behavior parity
NO_CHANGELOG=true
This pull request was AI-assisted by Isaac.
---------
Signed-off-by: Madhavendra Rathore <[email protected]>1 parent 9e96f22 commit addeeb7
103 files changed
Lines changed: 3781 additions & 46 deletions
File tree
- src
- main/java/com/databricks/jdbc
- api
- impl
- internal
- dbclient/impl/sqlexec
- test
- java/com/databricks/jdbc
- dbclient/impl/sqlexec
- integration/fakeservice/tests
- resources
- cloudfetchapi/metadatanullresolutiontests
- testgetcrossreference_fullyspecified/mappings
- testgetcrossreference_nullcatalogsexplicitschemas/mappings
- testgetcrossreference_nullcatalogsnullschemas/mappings
- testgetimportedkeys_fullyspecified/mappings
- testgetimportedkeys_nullcatalognullschema/mappings
- testgetprimarykeys_fullyspecified/mappings
- testgetprimarykeys_nullcatalogexplicitschema/mappings
- testgetprimarykeys_nullcatalognullschema/mappings
- sqlexecapi/metadatanullresolutiontests
- testcleanup_dropschemaandtables/mappings
- testgetcrossreference_fullyspecified/mappings
- testgetcrossreference_nullcatalogsexplicitschemas/mappings
- testgetcrossreference_nullcatalogsnullschemas/mappings
- testgetcrossreference_nullforeigntablereturnsempty/mappings
- testgetcrossreference_nullparenttablereturnsempty/mappings
- testgetimportedkeys_fullyspecified/mappings
- testgetimportedkeys_nullcatalognullschema/mappings
- testgetimportedkeys_nulltablereturnsempty/mappings
- testgetprimarykeys_explicitcatalognullschemareturnsempty/mappings
- testgetprimarykeys_fullyspecified/mappings
- testgetprimarykeys_nullcatalogexplicitschema/mappings
- testgetprimarykeys_nullcatalognullschema/mappings
- testgetprimarykeys_nulltablereturnsempty/mappings
- testsetup_createschemaandtables/mappings
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 25 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
367 | | - | |
| 366 | + | |
368 | 367 | | |
369 | 368 | | |
370 | 369 | | |
| |||
374 | 373 | | |
375 | 374 | | |
376 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
377 | 400 | | |
378 | 401 | | |
379 | 402 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
128 | 135 | | |
129 | 136 | | |
130 | 137 | | |
| |||
Lines changed: 82 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
327 | | - | |
| 326 | + | |
| 327 | + | |
328 | 328 | | |
329 | | - | |
| 329 | + | |
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
340 | 344 | | |
341 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
342 | 348 | | |
343 | 349 | | |
344 | 350 | | |
| |||
366 | 372 | | |
367 | 373 | | |
368 | 374 | | |
369 | | - | |
370 | | - | |
| 375 | + | |
| 376 | + | |
371 | 377 | | |
372 | | - | |
| 378 | + | |
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
| |||
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
383 | 393 | | |
384 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
385 | 397 | | |
386 | 398 | | |
387 | 399 | | |
| |||
434 | 446 | | |
435 | 447 | | |
436 | 448 | | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
441 | 453 | | |
442 | | - | |
443 | | - | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
444 | 458 | | |
445 | 459 | | |
446 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
447 | 480 | | |
448 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
449 | 484 | | |
450 | 485 | | |
451 | 486 | | |
452 | 487 | | |
453 | | - | |
454 | | - | |
455 | | - | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
456 | 491 | | |
457 | 492 | | |
458 | 493 | | |
| |||
506 | 541 | | |
507 | 542 | | |
508 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
509 | 573 | | |
510 | 574 | | |
511 | 575 | | |
| |||
Lines changed: 29 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | 627 | | |
631 | 628 | | |
632 | 629 | | |
| |||
946 | 943 | | |
947 | 944 | | |
948 | 945 | | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
953 | 964 | | |
954 | 965 | | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
959 | 970 | | |
960 | | - | |
961 | | - | |
| 971 | + | |
| 972 | + | |
962 | 973 | | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
967 | 977 | | |
968 | | - | |
969 | | - | |
| 978 | + | |
| 979 | + | |
970 | 980 | | |
971 | 981 | | |
972 | 982 | | |
| |||
1176 | 1186 | | |
1177 | 1187 | | |
1178 | 1188 | | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
1182 | 1189 | | |
1183 | 1190 | | |
1184 | 1191 | | |
| |||
1205 | 1212 | | |
1206 | 1213 | | |
1207 | 1214 | | |
1208 | | - | |
1209 | | - | |
1210 | | - | |
1211 | | - | |
1212 | 1215 | | |
1213 | 1216 | | |
1214 | 1217 | | |
| |||
0 commit comments