Skip to content

feat(bigquery-jdbc): migrate getPrimaryKeys to use BQ API#13691

Merged
keshavdandeva merged 5 commits into
mainfrom
jdbc/get-primary-keys
Jul 8, 2026
Merged

feat(bigquery-jdbc): migrate getPrimaryKeys to use BQ API#13691
keshavdandeva merged 5 commits into
mainfrom
jdbc/get-primary-keys

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

b/532245342

Migrates the getPrimaryKeys metadata methods in BigQueryDatabaseMetaData away from executing SQL queries on INFORMATION_SCHEMA tables, replacing them with native BigQuery Java Client SDK calls.

This PR also introduces the shared thread-safe concurrent dataset scanning infrastructure that will be utilized by subsequent metadata migrations.

Key Changes:

  1. getPrimaryKeys: Rewritten to fetch metadata using bigquery.getTable(...) and parsing table constraints in-memory.
  2. Concurrency Infrastructure:
    • Introduced processTargetTablesConcurrently(...) and processSingleTable(...) to handle concurrent metadata retrieval across target datasets using the metadata executor thread pool.
    • Added a short-circuit optimization for single target datasets to execute synchronously on the calling thread.
    • Extracted project list resolution into resolveTargetProjects(...) to support wildcard schema matching.
  3. Cleanup:
    • Deleted the obsolete DatabaseMetaData_GetPrimaryKeys.sql resource file.
    • Removed two obsolete SQL-parsing unit tests (testReadSqlFromFile and testMetadataMethodsDoNotInterfere) from BigQueryDatabaseMetaDataTest.java as they are no longer applicable.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the getPrimaryKeys method in BigQueryDatabaseMetaData to retrieve primary key metadata directly via the BigQuery API instead of executing a SQL query from a file. This change includes introducing concurrent processing of target tables and removing the obsolete SQL file and its associated tests. The code review feedback recommends wrapping potential BigQueryException runtime exceptions in SQLException to adhere to the JDBC API contract, and adding a finally block to cancel incomplete futures during concurrent execution to prevent thread leaks.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@keshavdandeva
keshavdandeva marked this pull request as ready for review July 8, 2026 00:24
@keshavdandeva
keshavdandeva requested review from a team as code owners July 8, 2026 00:24
List<String> projects = resolveTargetProjects(catalog);
List<DatasetId> datasetIds = new ArrayList<>(projects.size());
for (String project : projects) {
datasetIds.add(DatasetId.of(project, schema));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if specific project doesn't have that dataset? e.g. have 3 projects, but only 2 have dataset named foo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I used the same logic here to throw exception (instead of logging/swallowing when there is an error with one of the catalogs) but it shouldn't be that way.
I've updated processSingleTable to catch BigQueryException. During catalog-wide searches (catalog == null), if a dataset/table is missing (404) or inaccessible (403), we now log it at INFO level and skip it instead of failing the entire metadata query. If a specific catalog was queried, these errors will still correctly propagate

@logachev

logachev commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Please check if we have integration tests covering this.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

Please check if we have integration tests covering this.

Yes, we have testTableConstraints

@keshavdandeva
keshavdandeva requested a review from logachev July 8, 2026 17:21
@keshavdandeva
keshavdandeva merged commit 1951f49 into main Jul 8, 2026
204 checks passed
@keshavdandeva
keshavdandeva deleted the jdbc/get-primary-keys branch July 8, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants