You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fetching next batch of results using BigQuery's dbapi #3840
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'm not sure what you are asking. Under the covers the fetch_data method returns an iterator, so it would be possible to prefetch results, but why would you want to?
The DB-API specification says that arraysize must default to 1, so that's what the BigQuery DB-API does to stay compliant. As with any DB-API implementation, you must set the arraysize manually if you want a larger batch size.
Unless I am missing something, there is currently no way to fetch all rows for a query? The only workaround is to set arraysize to some arbitrary large number, because we don't know beforehand how many rows the result for the query will contain.
I'm able to reproduce this issue (only the first page is fetched) in the core API, not just the DB-API. By modifying the system test with 1000 rows and setting the page size to 100, I'm able to reproduce.
Activity
tswast commentedon Aug 18, 2017
I'm not sure what you are asking. Under the covers the
fetch_datamethod returns an iterator, so it would be possible to prefetch results, but why would you want to?The DB-API specification says that
arraysizemust default to 1, so that's what the BigQuery DB-API does to stay compliant. As with any DB-API implementation, you must set thearraysizemanually if you want a larger batch size.mxmzdlv commentedon Aug 18, 2017
Unless I am missing something, there is currently no way to fetch all rows for a query? The only workaround is to set
arraysizeto some arbitrary large number, because we don't know beforehand how many rows the result for the query will contain.tswast commentedon Aug 18, 2017
What's wrong with using
fetchall?But yes, for best performance you will need to increase the
arraysizeparameter before callingfetchalltswast commentedon Aug 18, 2017
fetchallshould not be limited byarraysize. It's just the batch size it uses to fetch results.mxmzdlv commentedon Aug 18, 2017
This is what I thought as well, but I've tried
fetchalland it just returns 1 row or what I specify forarraysize.tswast commentedon Aug 18, 2017
Ah, okay. I'll investigate further. Thanks for you patience.
tswast commentedon Aug 18, 2017
I'm able to reproduce the issue with this system test.
When arraysize is 1 (the default), only one result is returned when three are expected.
The unit tests are passing, but they mock out the core iterator class used, so I'm thinking the issue lies there or in how it is used.
tswast commentedon Aug 19, 2017
I think the problem is that HTTPIterator is looking for
nextPageTokenbut the getQueryResults response populatespageToken.tswast commentedon Aug 19, 2017
I'm able to reproduce this issue (only the first page is fetched) in the core API, not just the DB-API. By modifying the system test with 1000 rows and setting the page size to 100, I'm able to reproduce.
Working to fix in this branch: https://github.com/tswast/google-cloud-python/tree/bq-dbapi/bigquery
mxmzdlv commentedon Aug 19, 2017
Thank you for such a quick fix!
tswast commentedon Aug 21, 2017
Fix merged. It should be in the next release. (I don't know when that will be)
Update dependency google-cloud-scheduler to v1.3.0 [(#3840)](GoogleCl…