Skip to content

feat(bigquery-jdbc): migrate getExportedKeys to BQ API#13711

Merged
keshavdandeva merged 5 commits into
jdbc/getImportedKeysfrom
jdbc/getExportedKeys
Jul 9, 2026
Merged

feat(bigquery-jdbc): migrate getExportedKeys to BQ API#13711
keshavdandeva merged 5 commits into
jdbc/getImportedKeysfrom
jdbc/getExportedKeys

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

b/532245343

This PR migrates BigQueryDatabaseMetaData.getExportedKeys() from legacy INFORMATION_SCHEMA SQL queries to the native BigQuery Java SDK. This leverages the TableConstraints metadata directly, aligning it with the recent migrations of getPrimaryKeys and getImportedKeys.

Key Changes:

  • API Migration: Rewrote getExportedKeys to use TableConstraints fetched via the native SDK, eliminating the need for DatabaseMetaData_GetExportedKeys.sql.
  • Concurrent Scanning: Upgraded processTargetTablesConcurrently to dynamically list and concurrently scan all tables across target datasets when a parent table isn't explicitly provided.
  • Sorting Compliance: Added defineFkTableSortComparator to correctly sort result sets by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ as strictly required by the JDBC spec.
  • Code Cleanup: Removed obsolete SQL constants, .sql resource files, and dead helper methods (readSqlFromFile, replaceSqlParameters).
  • Testing: Added new integration test testGetExportedKeys

@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 getExportedKeys method in BigQueryDatabaseMetaData to retrieve foreign key constraints programmatically using the BigQuery client instead of executing an external SQL file, which has been removed. It also adds a corresponding integration test. Feedback on these changes includes a robustness and performance improvement for table listing to handle lazy pagination exceptions and filter by table type, as well as a recommendation to avoid hardcoding the GCP project ID in the integration tests to maintain portability.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 metadata retrieval in BigQueryDatabaseMetaData by introducing asynchronous queue population via populateQueueAsync and rewriting getExportedKeys to process target tables concurrently instead of executing SQL from a file. It also removes several unused imports, methods, and the SQL template file, and adds integration tests for getExportedKeys. The review feedback highlights a critical thread leak risk: because populateQueueAsync returns void, the returned Future is discarded, meaning background tasks cannot be cancelled if a ResultSet is closed early. The reviewer recommends returning Future<?> from populateQueueAsync and passing it to BigQueryJsonResultSet.of across all invocations. Additionally, they suggest cancelling already submitted tasks in processTargetTablesConcurrently if a BigQueryException is thrown to prevent resource leaks.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 BigQueryDatabaseMetaData to retrieve exported keys programmatically via metadata APIs instead of executing SQL from a file, and introduces asynchronous queue population (populateQueueAsync) across several metadata methods. It also updates table processing to handle null table names concurrently and adds integration tests for getExportedKeys. Feedback suggests improving exception handling in processTargetTablesConcurrently by explicitly cancelling outstanding tasks and properly restoring the thread's interrupted status if waitForTasksCompletion fails or is interrupted.

@keshavdandeva
keshavdandeva marked this pull request as ready for review July 8, 2026 23:08
@keshavdandeva
keshavdandeva requested review from a team as code owners July 8, 2026 23:08
@keshavdandeva
keshavdandeva merged commit 1e05031 into jdbc/getImportedKeys Jul 9, 2026
114 checks passed
@keshavdandeva
keshavdandeva deleted the jdbc/getExportedKeys branch July 9, 2026 13:23
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