-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add sample for fetching total_rows from query results. #7217
Conversation
bigquery/docs/snippets.py
Outdated
results = query_job.result() # Waits for query to complete. | ||
next(iter(results)) # Fetch the first page of results, which contains total_rows. | ||
print("Got {} rows.".format(results.total_rows)) | ||
# [START bigquery_query_total_rows] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
END?
bigquery/docs/snippets.py
Outdated
@@ -2225,6 +2225,32 @@ def test_client_query_legacy_sql(client): | |||
# [END bigquery_query_legacy] | |||
|
|||
|
|||
def test_client_query_total_rows(client, capsys): | |||
"""Run a query an just check for how many rows.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an/and/
Would fetching the first page of |
@yiga2 Calling I agree that the way I show in this sample is a bit awkward, and I was thinking about fetching the first page automatically in #4152, but I changed my mind about prefetching, since it could mean an extra unnecessary API request if someone just cares that a query completes and not the actual result rows. Perhaps we could find a way to pass the |
@tswast any further consideration on getting |
@yiga2 I still think it's a good idea. I just haven't gotten around to. We're open to PRs. The change would likely be to the |
@tswast Feel free to bundle with other enhancements as PR would be very light otherwise. Suggested code change, after
total_rows = self._query_results.total_rows
|
@tswast any feedback on this ? |
@yiga2 I've prepared #7622 which addresses this issue, but in a slightly more complicated way than we propose here because I wanted to also handle more cases where |
Cool - thanks Tim ! |
In response to feedback internally Bug 123578325, add a sample (acts as a system test, too) which shows how to populate the
total_rows
value.