-
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
Make total_rows available on RowIterator before iteration #7622
Conversation
self._total_rows = None | ||
if table is not None and hasattr(table, "num_rows"): | ||
self._total_rows = table.num_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.
This could simplify down to:
self._total_rows = getattr(table, "num_rows", None)
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.
Thanks. Done in 99441d7.
rows = list(result) | ||
self.assertEqual(len(rows), 1) | ||
self.assertEqual(rows[0].col1, "abc") | ||
self.assertEqual(result.total_rows, 1) |
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.
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.
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.
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
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_rows
has a fullTable
resource, this PR is based on #7621.