Repository navigation
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new BigQuery sample script, bigquery_search_subset_columns.py, which demonstrates how to search a specific subset of columns in a table using the SEARCH function, along with its corresponding unit tests and configuration files. The feedback suggests updating noxfile_config.py to ensure only the oldest and newest supported Python versions are tested, and refactoring the unit tests to use mock.MagicMock instead of fragile lambda functions for mocking the BigQuery client constructor.
| monkeypatch.setattr( | ||
| bigquery_search_subset_columns.bigquery, | ||
| "Client", | ||
| lambda project=None: mock_client, | ||
| ) |
There was a problem hiding this comment.
Using a lambda with a specific signature like lambda project=None to mock a class constructor is fragile. If the initialization arguments of bigquery.Client change or if other arguments are passed, this will raise a TypeError. Using mock.MagicMock(return_value=mock_client) is the standard, robust way to mock a class constructor in Python.
| monkeypatch.setattr( | |
| bigquery_search_subset_columns.bigquery, | |
| "Client", | |
| lambda project=None: mock_client, | |
| ) | |
| monkeypatch.setattr( | |
| bigquery_search_subset_columns.bigquery, | |
| "Client", | |
| mock.MagicMock(return_value=mock_client), | |
| ) |
| monkeypatch.setattr( | ||
| bigquery_search_subset_columns.bigquery, | ||
| "Client", | ||
| lambda project=None: mock_client, | ||
| ) |
There was a problem hiding this comment.
Using a lambda with a specific signature like lambda project=None to mock a class constructor is fragile. If the initialization arguments of bigquery.Client change or if other arguments are passed, this will raise a TypeError. Using mock.MagicMock(return_value=mock_client) is the standard, robust way to mock a class constructor in Python.
| monkeypatch.setattr( | |
| bigquery_search_subset_columns.bigquery, | |
| "Client", | |
| lambda project=None: mock_client, | |
| ) | |
| monkeypatch.setattr( | |
| bigquery_search_subset_columns.bigquery, | |
| "Client", | |
| mock.MagicMock(return_value=mock_client), | |
| ) |
1a7a75a to
77f1f98
Compare
… specific subset of table columns Problem: The BigQuery documentation (https://cloud.google.com/bigquery/docs/search) needs a standalone, tested Python code sample demonstrating how to search a specific subset of table columns (region tag `bigquery_search_subset_columns`). Solution: - Add `search_subset_columns(project_id: str) -> None` in `bigquery/search/bigquery_search_subset_columns.py` (Restrict a BigQuery SEARCH query to a specific struct of table columns.) - Add unit tests (`bigquery/search/bigquery_search_subset_columns_test.py`) covering both the success path and API error handling (`GoogleAPICallError`)
77f1f98 to
f65af11
Compare
… specific subset of table columns
Problem:
The BigQuery documentation (https://cloud.google.com/bigquery/docs/search) needs a standalone, tested Python code sample demonstrating how to search a specific subset of table columns (region tag
bigquery_search_subset_columns).Solution:
search_subset_columns(project_id: str) -> Noneinbigquery/search/bigquery_search_subset_columns.py(Restrict a BigQuery SEARCH query to a specific struct of table columns.)bigquery/search/bigquery_search_subset_columns_test.py) covering both the success path and API error handling (GoogleAPICallError)Description
Fixes #
Checklist
Testing
Compliance & Style
Post-Approval Actions