Add sample for fetching total_rows from query results.#7217
Add sample for fetching total_rows from query results.#7217tswast merged 2 commits intogoogleapis:masterfrom
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] |
bigquery/docs/snippets.py
Outdated
|
|
||
|
|
||
| def test_client_query_total_rows(client, capsys): | ||
| """Run a query an just check for how many rows.""" |
|
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_rowsvalue.