Skip to content

Commit 96c4420

Browse files
refactor(bigquery-jdbc): optimize thread management and unify discovery logic in DatabaseMetaData methods (#13560)
b/520407325 b/520406763 This PR refactors and optimizes the database metadata retrieval methods in the BigQuery JDBC driver. It resolves thread management inefficiencies, eliminates duplicate API blocks, ensures consistent project discovery support, and implements strict, fail-fast error propagation across all asynchronous metadata methods. ## Key Changes ### 1. Catalog-Based Routing in `getSchemas` * **Synchronous Single-Catalog Path**: If a specific catalog (project) is requested, `getSchemas` now executes completely synchronously on the calling thread, eliminating background executor and queue overhead. * **Parallel Multi-Catalog Path**: If no catalog is specified, the query executor runs parallel scans across all accessible projects (primary, additional, and discovered) in the background. ### 2. Unified Dataset Discovery & Deduplication * Introduced a single, shared helper method `fetchMatchingDatasets` to serve as the sole entry point for listing and filtering datasets. * Deduplicated dataset-listing logic across **7 metadata methods** (`getSchemas`, `getTables`, `getColumns`, `getProcedures`, `getProcedureColumns`, `getFunctions`, and `getFunctionColumns`), ensuring consistent support for project discovery and SQL wildcard matching across all of them. ### 3. Strict Fail-Fast Error & Interruption Handling * **Preventing Silent Truncation**: Background metadata fetchers used to silently swallow `InterruptedException`s and `ExecutionException`s, returning partial or empty results to the user (which severely violates the JDBC contract during query timeouts or connection drops). * **Consistent Propagation**: All 7 background methods now strictly push an `SQLException` to the client's queue whenever an interruption or runtime error occurs, ensuring the user gets an explicit failure when calling `rs.next()`. * **Boilerplate Elimination**: Extracted the complex error-handling and queue-finalization boilerplate into centralized helper methods (`handleFetcherException` and `finalizeFetcher`). This removed over 50 lines of duplicate code, deleted 14+ redundant `isInterrupted()` checks, and established a clean, unified standard for all asynchronous metadata threads.
1 parent 485ae6f commit 96c4420

4 files changed

Lines changed: 211 additions & 299 deletions

File tree

0 commit comments

Comments
 (0)