test(bigquery-jdbc): add unit tests for constraint metadata methods#13719
test(bigquery-jdbc): add unit tests for constraint metadata methods#13719keshavdandeva wants to merge 3 commits into
Conversation
fa89f61 to
d95a9f2
Compare
There was a problem hiding this comment.
Code Review
This pull request adds comprehensive unit tests to BigQueryDatabaseMetaDataTest.java for verifying metadata retrieval methods such as getPrimaryKeys, getImportedKeys, getExportedKeys, and getCrossReference. The feedback recommends improving the robustness of Mockito varargs matching by using array matchers and wrapping ResultSet instances in try-with-resources blocks to prevent potential resource leaks.
…` to BQ API (#13692) b/532249777 This PR migrates the `getImportedKeys` and `getCrossReference` JDBC metadata methods in `BigQueryDatabaseMetaData` to retrieve constraints natively via the Google Cloud Java Client API instead of running legacy raw SQL files on BigQuery. ## Changes ### **API-based Implementations** - Migrated `getImportedKeys(...)` to fetch and scan foreign keys from standard table definitions. - Migrated `getCrossReference(...)` to matching parent and foreign table references using client-side definitions. - Utilized the shared parallel table processor utilities (`processTargetTablesConcurrently(...)` and `processSingleTable(...)`) to run dataset scans concurrently. ### **Sorting & Correctness** - Separated sorting behavior according to the JDBC specification: - `getImportedKeys` is sorted by parent table: `PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, KEY_SEQ`. Introduced `definePkTableSortComparator` for this. - `getCrossReference` (and future `getExportedKeys`) is sorted by child table: `FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ`. Uses `defineFkTableSortComparator`. - Introduced a private helper `matchesOrNullWildcard(...)` to simplify and clean up catalog/schema bounds comparisons.
d95a9f2 to
0349c8e
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates mock expectations in BigQueryDatabaseMetaDataTest to use array types for list options, wraps ResultSet usages in try-with-resources blocks, and adds new unit tests for retrieving primary, imported, exported, and cross-referenced keys. The review feedback suggests removing the redundant mockDatasetIteration helper method as it is not required by the metadata methods under test, and expanding the test suite to cover composite keys to verify multi-column handling and correct sequence ordering.
b/532929906
This PR introduces unit testing for the 4 recently migrated constraint metadata methods (
getPrimaryKeys,getImportedKeys,getExportedKeys, andgetCrossReference) inBigQueryDatabaseMetaDataTest, alongside some important test infrastructure hardening.Key Changes:
_hasKeys) and empty state (_noKeys) for every metadata endpoint, ensuring BigQuery'sTableConstraintsstructure is properly translated into JDBC standard formats (PKTABLE_NAME,KEY_SEQ, etc.) without relying on slow integration tests.TableDefinitionsetup into clean helper methods (mockDatasetIteration,mockTableWithConstraints).any(BigQuery.*ListOption.class)to array matchers (any(BigQuery.*ListOption[].class)). This prevents spontaneousNullPointerExceptions if production code alters the number of varargs it passes.ResultSetlifecycles usingtry-with-resources, ensuring noAutoCloseableresources are leaked during test execution.