From 7c0167e8c98164aa1d70c71a923aba22c4f08aed Mon Sep 17 00:00:00 2001 From: Matteo Danieli Date: Tue, 22 Dec 2015 15:35:00 +0100 Subject: [PATCH 1/2] Take into account limit argument when returning rows --- bigquery/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigquery/client.py b/bigquery/client.py index 860b887..621c67c 100644 --- a/bigquery/client.py +++ b/bigquery/client.py @@ -327,13 +327,13 @@ def get_query_rows(self, job_id, offset=None, limit=None, timeout=0): records = [self._transform_row(row, schema) for row in rows] # Append to records if there are multiple pages for query results - while page_token: + while limit is None and page_token or len(records) < limit: query_reply = self.get_query_results(job_id, offset=offset, limit=limit, page_token=page_token, timeout=timeout) page_token = query_reply.get("pageToken") rows = query_reply.get('rows', []) records += [self._transform_row(row, schema) for row in rows] - return records + return records[:limit] if limit else records def check_dataset(self, dataset_id): """Check to see if a dataset exists. From d454a3d64fb593ce324c2bcbfea4adc4164e3f12 Mon Sep 17 00:00:00 2001 From: Matteo Danieli Date: Tue, 22 Dec 2015 19:51:32 +0100 Subject: [PATCH 2/2] Fix stopping condition --- bigquery/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigquery/client.py b/bigquery/client.py index 621c67c..1ac3cb3 100644 --- a/bigquery/client.py +++ b/bigquery/client.py @@ -327,7 +327,7 @@ def get_query_rows(self, job_id, offset=None, limit=None, timeout=0): records = [self._transform_row(row, schema) for row in rows] # Append to records if there are multiple pages for query results - while limit is None and page_token or len(records) < limit: + while page_token and (not limit or len(records) < limit): query_reply = self.get_query_results(job_id, offset=offset, limit=limit, page_token=page_token, timeout=timeout) page_token = query_reply.get("pageToken")