Skip to content

Fetching next batch of results using BigQuery's dbapi #3840

Closed
@mxmzdlv

Description

@mxmzdlv

Currently, the maximum number of rows that you can get when iterating using fetchmany, fetchall or fetchone is limited by arraysize.

I see that those methods are using iterator returned by _query_data.fetch_data() with max_results set to arraysize
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/36304f7448677cff2f89558ef87c374e904a0492/bigquery/google/cloud/bigquery/dbapi/cursor.py#L171-L172

However, shouldn't it automatically fetch the next page of results when we are finished iterating over the current batch of results? Otherwise, it makes it impossible to retrieve full results from the query without settingarraysize to an arbitrary large number.

Here is what I've tried:

cursor.execute('SELECT * FROM dataset.table')

while True:
    rows = cursor.fetchmany(5000)
    if not rows:
        break

    for row in rows:
        print(row)
cursor.execute('SELECT * FROM dataset.table')

row = cursor.fetchone()
while row:
   print(row)
   row = cursor.fetchone()

I am using google-cloud-bigquery 0.26.0

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions