@@ -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 = []
@@ -264,10 +270,6 @@ def fetchmany(self, size=None):
264270 def fetchall (self ):
265271 """Fetch all remaining results from the last ``execute*()`` call.
266272
267- .. note::
268- The ``arraysize`` attribute can affect the performance of this
269- operation. Make sure to set it to appropriate batch size beforehand.
270-
271273 :rtype: List[tuple]
272274 :returns: A list of all the rows in the results.
273275 :raises: :class:`~google.cloud.bigquery.dbapi.InterfaceError`
0 commit comments