Skip to content

Commit

Permalink
BigQuery: Change the default value of Cursor instances' arraysize att…
Browse files Browse the repository at this point in the history
…ribute to None (#9199)

* Add performance note to fetchall() docs

* Set default cursor arraysize to None

Let the backend pick the most appropriate size automatically, instead
of enforcing the size of 1 on it (despite thise being a deviation from
PEP 249).
  • Loading branch information
plamut authored Sep 12, 2019
1 parent 1a2311a commit 69ff0bf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bigquery/google/cloud/bigquery/dbapi/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def __init__(self, connection):
# cannot be determined by the interface.
self.rowcount = -1
# Per PEP 249: The arraysize attribute defaults to 1, meaning to fetch
# a single row at a time.
self.arraysize = 1
# a single row at a time. However, we deviate from that, and set the
# default to None, allowing the backend to automatically determine the
# most appropriate size.
self.arraysize = None
self._query_data = None
self._query_job = None

Expand Down Expand Up @@ -241,15 +243,19 @@ def fetchmany(self, size=None):
:type size: int
:param size:
(Optional) Maximum number of rows to return. Defaults to the
``arraysize`` property value.
``arraysize`` property value. If ``arraysize`` is not set, it
defaults to ``1``.
:rtype: List[tuple]
:returns: A list of rows.
:raises: :class:`~google.cloud.bigquery.dbapi.InterfaceError`
if called before ``execute()``.
"""
if size is None:
size = self.arraysize
# Since self.arraysize can be None (a deviation from PEP 249),
# use an actual PEP 249 default of 1 in such case (*some* number
# is needed here).
size = self.arraysize if self.arraysize else 1

self._try_fetch(size=size)
rows = []
Expand Down

0 comments on commit 69ff0bf

Please sign in to comment.