Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: search statistics #1616

Merged
merged 56 commits into from
Sep 2, 2023
Merged

feat: search statistics #1616

merged 56 commits into from
Sep 2, 2023

Conversation

chalmerlowe
Copy link
Collaborator

Adds a feature to display search statistics in support of the following customer request: https://buganizer.corp.google.com/issues/290679162

Includes several classes to encapsulate the data found here:
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#searchstatistics

Also includes a function to access the data in the classes.

@chalmerlowe chalmerlowe requested review from a team as code owners July 20, 2023 10:26
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the googleapis/python-bigquery API. labels Jul 20, 2023
@shollyman shollyman requested review from shollyman and removed request for farhan0102 July 20, 2023 15:57
Copy link
Contributor

@shollyman shollyman left a comment

Choose a reason for hiding this comment

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

Good start on the basic structure. This is an output-only stat so no need for a setter, but we'll need all the unit testing and a similar IT test to java using a query that invokes the search() sql function.

"""docstring"""

stats = self._job_statistics().get("searchStatistics")
return SearchStats.from_api_repr(stats)
Copy link
Contributor

Choose a reason for hiding this comment

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

need to handle the not-present case, e.g. if stats is not None:


@classmethod
def from_api_repr(cls, stats: Dict[str, Any]):
mode = stats.get("indexUsageMode", "INDEX_USAGE_MODE_UNSPECIFIED")
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, we want to avoid the library injecting values not present in the API response, so returning the default value here may not be more desirable than empty/none.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Aug 9, 2023
@chalmerlowe chalmerlowe added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Aug 23, 2023
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Aug 23, 2023
tests/unit/job/test_query_stats.py Outdated Show resolved Hide resolved
tests/unit/job/test_query_stats.py Outdated Show resolved Hide resolved
Copy link
Contributor

@shollyman shollyman left a comment

Choose a reason for hiding this comment

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

After some more reading, I think the attribute approach is sufficient vs explicit property annotations.

Main concern is about attribute defaults. Typically None is better when users are trying to disambiguate between presence of a value vs the empty value, but happy to talk about this more. Swapping the default impacts typing, unit tests, etc.

google/cloud/bigquery/job/query.py Outdated Show resolved Hide resolved
google/cloud/bigquery/job/query.py Outdated Show resolved Hide resolved
google/cloud/bigquery/job/query.py Outdated Show resolved Hide resolved
@chalmerlowe chalmerlowe merged commit b930e46 into main Sep 2, 2023
7 checks passed
@chalmerlowe chalmerlowe deleted the feat-search-statistics branch September 2, 2023 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants