Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8482f47

Browse files
tswastparthea
andauthored
fix: keepRowIterator.total_rows populated after iteration (#1748)
* fix: keep `RowIterator.total_rows` populated after iterationThis was being reset in some cases whenthe rows were all available in thefirst page of results.* Update google/cloud/bigquery/table.pyCo-authored-by: Anthonios Partheniou <partheniou@google.com>---------Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parentab73796 commit8482f47

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

‎google/cloud/bigquery/table.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,9 +2997,9 @@ def _rows_page_start(iterator, page, response):
29972997
page._columns=_row_iterator_page_columns(iterator._schema,response)
29982998

29992999
total_rows=response.get("totalRows")
3000+
# Don't reset total_rows if it's not present in the next API response.
30003001
iftotal_rowsisnotNone:
3001-
total_rows=int(total_rows)
3002-
iterator._total_rows=total_rows
3002+
iterator._total_rows=int(total_rows)
30033003

30043004

30053005
# pylint: enable=unused-argument

‎tests/unit/test_table.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2201,9 +2201,18 @@ def test_iterate_with_cached_first_page(self):
22012201
path="/foo"
22022202
api_request=mock.Mock(return_value={"rows":rows})
22032203
row_iterator=self._make_one(
2204-
_mock_client(),api_request,path,schema,first_page_response=first_page
2204+
_mock_client(),
2205+
api_request,
2206+
path,
2207+
schema,
2208+
first_page_response=first_page,
2209+
total_rows=4,
22052210
)
2211+
self.assertEqual(row_iterator.total_rows,4)
22062212
rows=list(row_iterator)
2213+
# Total rows should be maintained, even though subsequent API calls
2214+
# don't include it.
2215+
self.assertEqual(row_iterator.total_rows,4)
22072216
self.assertEqual(len(rows),4)
22082217
self.assertEqual(rows[0].age,27)
22092218
self.assertEqual(rows[1].age,28)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp