Skip to content

Commit

Permalink
Simplify RowIterator constructor. Add test comments.
Browse files Browse the repository at this point in the history
Use getattr instead of protecting with hasattr in the RowIterator
constructor.

Add comments about intentionally conflicting values for total_rows.
  • Loading branch information
tswast committed Apr 1, 2019
1 parent 73b46b9 commit 99441d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 4 additions & 8 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,17 +1298,13 @@ def __init__(
page_start=_rows_page_start,
next_token="pageToken",
)
self._schema = schema
self._field_to_index = _helpers._field_to_index_mapping(schema)

self._total_rows = None
if table is not None and hasattr(table, "num_rows"):
self._total_rows = table.num_rows

self._page_size = page_size
self._table = table
self._selected_fields = selected_fields
self._project = client.project
self._schema = schema
self._selected_fields = selected_fields
self._table = table
self._total_rows = getattr(table, "num_rows", None)

def _get_next_page_response(self):
"""Requests the next page from the path provided.
Expand Down
4 changes: 4 additions & 0 deletions bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,8 @@ def test_result(self):
"totalRows": "2",
}
tabledata_resource = {
# Explicitly set totalRows to be different from the query response.
# to test update during iteration.
"totalRows": "1",
"pageToken": None,
"rows": [{"f": [{"v": "abc"}]}],
Expand All @@ -4038,6 +4040,8 @@ def test_result(self):
rows = list(result)
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0].col1, "abc")
# Test that the total_rows property has changed during iteration, based
# on the response from tabledata.list.
self.assertEqual(result.total_rows, 1)

def test_result_w_empty_schema(self):
Expand Down

0 comments on commit 99441d7

Please sign in to comment.