Skip to content

Commit e376b0f

Browse files
plamutemar-kar
authored andcommitted
BigQuery: Change the default value of Cursor instances' arraysize attribute to None (googleapis#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).
1 parent aa5a335 commit e376b0f

File tree

1 file changed

+10
-4
lines changed
  • bigquery/google/cloud/bigquery/dbapi

1 file changed

+10
-4
lines changed

bigquery/google/cloud/bigquery/dbapi/cursor.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ def __init__(self, connection):
6161
# cannot be determined by the interface.
6262
self.rowcount = -1
6363
# Per PEP 249: The arraysize attribute defaults to 1, meaning to fetch
64-
# a single row at a time.
65-
self.arraysize = 1
64+
# a single row at a time. However, we deviate from that, and set the
65+
# default to None, allowing the backend to automatically determine the
66+
# most appropriate size.
67+
self.arraysize = None
6668
self._query_data = None
6769
self._query_job = None
6870

@@ -241,15 +243,19 @@ def fetchmany(self, size=None):
241243
:type size: int
242244
:param size:
243245
(Optional) Maximum number of rows to return. Defaults to the
244-
``arraysize`` property value.
246+
``arraysize`` property value. If ``arraysize`` is not set, it
247+
defaults to ``1``.
245248
246249
:rtype: List[tuple]
247250
:returns: A list of rows.
248251
:raises: :class:`~google.cloud.bigquery.dbapi.InterfaceError`
249252
if called before ``execute()``.
250253
"""
251254
if size is None:
252-
size = self.arraysize
255+
# Since self.arraysize can be None (a deviation from PEP 249),
256+
# use an actual PEP 249 default of 1 in such case (*some* number
257+
# is needed here).
258+
size = self.arraysize if self.arraysize else 1
253259

254260
self._try_fetch(size=size)
255261
rows = []

0 commit comments

Comments
 (0)