Make total_rows available on RowIterator before iteration#7622
Merged
tswast merged 3 commits intogoogleapis:masterfrom Apr 16, 2019
Merged
Make total_rows available on RowIterator before iteration#7622tswast merged 3 commits intogoogleapis:masterfrom
tswast merged 3 commits intogoogleapis:masterfrom
Conversation
tseaver
suggested changes
Mar 30, 2019
|
|
||
| self._total_rows = None | ||
| if table is not None and hasattr(table, "num_rows"): | ||
| self._total_rows = table.num_rows |
Contributor
There was a problem hiding this comment.
This could simplify down to:
self._total_rows = getattr(table, "num_rows", None)| rows = list(result) | ||
| self.assertEqual(len(rows), 1) | ||
| self.assertEqual(rows[0].col1, "abc") | ||
| self.assertEqual(result.total_rows, 1) |
Contributor
There was a problem hiding this comment.
Do you mean to test explicitly the case where the initial query result resource has a different number of rows than the count got by iteration? If so, then a comment above stating that would be helpful.
Contributor
Author
There was a problem hiding this comment.
Yes, that's intentional. You're right that it looks wrong. I suspect it'll be quite rare in practice, but it can happen, especially when append query jobs are involved. Added comments in 99441d7.
After running a query, the total number of rows is available from the call to the getQueryResults API. This commit plumbs the total rows through to the faux Table created in QueryJob.results and then on through to the RowIterator created by list_rows.
Use getattr instead of protecting with hasattr in the RowIterator constructor. Add comments about intentionally conflicting values for total_rows.
34704c3 to
99441d7
Compare
This was referenced Apr 2, 2019
shollyman
approved these changes
Apr 16, 2019
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.
After running a query, the total number of rows is available from the
call to the getQueryResults API. This commit plumbs the total rows
through to the faux Table created in QueryJob.results and then on
through to the RowIterator created by list_rows.
Fixes #6117.
Since this feature is more useful when
list_rowshas a fullTableresource, this PR is based on #7621.