Repository navigation
refactor(bigquery): move tests into tests/ and apply review feedback to merged samples - #14754
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates BigQuery search and vector index scripts and their corresponding tests. Specifically, it modifies the search index creation to use 'CREATE SEARCH INDEX IF NOT EXISTS' and updates the exception handling to catch 'exceptions.NotFound' instead of 'exceptions.AlreadyExists'. Additionally, it refactors error messages for missing tables or datasets in the vector index drop script and updates unit tests to use empty list results for mock query jobs. There are no review comments, so I have no feedback to provide.
iennae
force-pushed
the
fix/bq-merged-samples-cleanup
branch
from
November 3, 2026 23:32
2ac3d30 to
260d2cb
Compare
… up test mocks Problem: Following review feedback across the BigQuery sample PRs (#14714, #14715, #14717): - `bigquery_create_search_index.py` should use `CREATE SEARCH INDEX IF NOT EXISTS` and handle `exceptions.NotFound` when the parent table or dataset is missing. - `bigquery_drop_vector_index.py` `NotFound` error message should reflect that `DROP VECTOR INDEX IF EXISTS` raises `NotFound` when the parent table or dataset is missing. - Unit tests in `bigquery_create_search_index_test.py`, `bigquery_drop_vector_index_test.py`, and `bigquery_query_manifest_external_table_test.py` defined unused mock attributes (`mock_row` on DDL statements and `mock_job.statement_type` on SELECT queries). Solution: - Restore `CREATE SEARCH INDEX IF NOT EXISTS` and catch `exceptions.NotFound` in `bigquery/search/bigquery_create_search_index.py` and its unit test. - Update the `NotFound` error message in `bigquery/vector_search/bigquery_drop_vector_index.py`. - Remove unused `mock_row` and `mock_job.statement_type` setup in the three corresponding unit test files.
…to merged samples
Problem:
Reviewers on the BigQuery Data Cloud sample PRs asked for three changes:
combined DDL + SELECT scripts were hard to read, every sample wrapped its
API call in a generic try/except that printed to stderr and swallowed the
error, and the unit tests patched the client with raw strings and asserted
on stderr text. Each area folder also mixed *_test.py files with the
samples themselves, cluttering the folders readers browse.
Solution:
- Move every unit test in bigquery/{stored_procedures,transactions,search,
vector_search,biglake,federated_queries,data_profile_scan} into a tests/
subdirectory, add __init__.py to each area and its tests/ folder, and
import the sample with `from .. import <sample>` (same layout as
cloud_scheduler/snippets). noxfile-template already collects `tests`.
- Run DDL/scripts and the follow-up SELECT as separate client.query()
calls (bigquery_query_iceberg_table, bigquery_multi_statement_transaction).
- Remove the generic try/except stderr blocks (and the now-unused sys and
google.api_core.exceptions imports) so GoogleAPICallError propagates.
- Tests patch the client with monkeypatch.setattr(<sample>.bigquery,
"Client", ...) / mock.patch.object and assert
pytest.raises(exceptions.GoogleAPICallError) for the error path.
Verified per area with the noxfile-template flake8 arguments (google import
order, flake8-annotations), black, and pytest: 42 passed.
iennae
force-pushed
the
fix/bq-merged-samples-cleanup
branch
from
November 17, 2026 04:43
260d2cb to
0930c0b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Applies reviewer feedback from the BigQuery Data Cloud sample PRs to the 21 samples that have already merged, and moves their unit tests out of the sample folders.
Layout: tests in
tests/In
bigquery/{stored_procedures,transactions,search,vector_search,biglake,federated_queries,data_profile_scan}:*_test.pymoves totests/<sample>_test.py.__init__.pyto each folder and to itstests/; tests import the sample withfrom .. import <sample>.cloud_scheduler/snippets/.noxfile-template.pyalready collects atestsdirectory.Review feedback
SELECTrun as separate queries:bigquery_multi_statement_transactionandbigquery_query_iceberg_tablenow run the script/DDL and the follow-upSELECTas twoclient.query()calls.try/except: removed the stderr-printingtry/exceptblocks (and the unusedsys/google.api_core.exceptionsimports), soGoogleAPICallErrorpropagates to the caller.monkeypatch.setattr(<sample>.bigquery, "Client", ...)/mock.patch.object, and assertpytest.raises(exceptions.GoogleAPICallError)on the error path.IF NOT EXISTSinbigquery_create_search_index, removing unused mock attributes).Testing
Ran in each of the 7 folders with the
noxfile-templatelint arguments (google import order,flake8-annotations), plusblackandpytest: lint passes, 42 tests pass.The 15 open single-sample PRs (#14737, #14739, #14741–#14753) will be rebased onto this layout once it merges.