@@ -5612,6 +5612,71 @@ def _bigquery_timestamp_float_repr(ts_float):
56125612 method = "GET" , path = "/%s" % PATH , query_params = {}, timeout = 7.5
56135613 )
56145614
5615+ def test_list_rows_w_start_index_w_page_size (self ):
5616+ from google .cloud .bigquery .schema import SchemaField
5617+ from google .cloud .bigquery .table import Table
5618+ from google .cloud .bigquery .table import Row
5619+
5620+ PATH = "projects/%s/datasets/%s/tables/%s/data" % (
5621+ self .PROJECT ,
5622+ self .DS_ID ,
5623+ self .TABLE_ID ,
5624+ )
5625+
5626+ page_1 = {
5627+ "totalRows" : 4 ,
5628+ "pageToken" : "some-page-token" ,
5629+ "rows" : [
5630+ {"f" : [{"v" : "Phred Phlyntstone" }]},
5631+ {"f" : [{"v" : "Bharney Rhubble" }]},
5632+ ],
5633+ }
5634+ page_2 = {
5635+ "totalRows" : 4 ,
5636+ "rows" : [
5637+ {"f" : [{"v" : "Wylma Phlyntstone" }]},
5638+ {"f" : [{"v" : "Bhettye Rhubble" }]},
5639+ ],
5640+ }
5641+ creds = _make_credentials ()
5642+ http = object ()
5643+ client = self ._make_one (project = self .PROJECT , credentials = creds , _http = http )
5644+ conn = client ._connection = make_connection (page_1 , page_2 )
5645+ full_name = SchemaField ("full_name" , "STRING" , mode = "REQUIRED" )
5646+ table = Table (self .TABLE_REF , schema = [full_name ])
5647+ iterator = client .list_rows (table , max_results = 4 , page_size = 2 , start_index = 1 )
5648+ pages = iterator .pages
5649+ rows = list (six .next (pages ))
5650+ extra_params = iterator .extra_params
5651+ f2i = {"full_name" : 0 }
5652+ self .assertEqual (len (rows ), 2 )
5653+ self .assertEqual (rows [0 ], Row (("Phred Phlyntstone" ,), f2i ))
5654+ self .assertEqual (rows [1 ], Row (("Bharney Rhubble" ,), f2i ))
5655+
5656+ rows = list (six .next (pages ))
5657+
5658+ self .assertEqual (len (rows ), 2 )
5659+ self .assertEqual (rows [0 ], Row (("Wylma Phlyntstone" ,), f2i ))
5660+ self .assertEqual (rows [1 ], Row (("Bhettye Rhubble" ,), f2i ))
5661+ self .assertEqual (extra_params , {"startIndex" : 1 })
5662+
5663+ conn .api_request .assert_has_calls (
5664+ [
5665+ mock .call (
5666+ method = "GET" ,
5667+ path = "/%s" % PATH ,
5668+ query_params = {"startIndex" : 1 , "maxResults" : 2 },
5669+ timeout = None ,
5670+ ),
5671+ mock .call (
5672+ method = "GET" ,
5673+ path = "/%s" % PATH ,
5674+ query_params = {"pageToken" : "some-page-token" , "maxResults" : 2 },
5675+ timeout = None ,
5676+ ),
5677+ ]
5678+ )
5679+
56155680 def test_list_rows_empty_table (self ):
56165681 response = {"totalRows" : "0" , "rows" : []}
56175682 creds = _make_credentials ()
0 commit comments