@@ -35,12 +35,18 @@ class Connection(object):
3535 A client that uses the faster BigQuery Storage API to fetch rows from
3636 BigQuery. If not passed, it is created using the same credentials
3737 as ``client`` (provided that BigQuery Storage dependencies are installed).
38-
39- If both clients are available, ``bqstorage_client`` is used for
40- fetching query results.
38+ prefer_bqstorage_client (Optional[bool]):
39+ Prefer the BigQuery Storage client over the REST client. If Storage
40+ client isn't available, fall back to the REST client. Defaults to
41+ ``True``.
4142 """
4243
43- def __init__ (self ,client = None ,bqstorage_client = None ):
44+ def __init__ (
45+ self ,
46+ client = None ,
47+ bqstorage_client = None ,
48+ prefer_bqstorage_client = True ,
49+ ):
4450if client is None :
4551client = bigquery .Client ()
4652self ._owns_client = True
@@ -49,7 +55,10 @@ def __init__(self, client=None, bqstorage_client=None):
4955
5056# A warning is already raised by the BQ Storage client factory factory if
5157# instantiation fails, or if the given BQ Storage client instance is outdated.
52- if bqstorage_client is None :
58+ if not prefer_bqstorage_client :
59+ bqstorage_client = None
60+ self ._owns_bqstorage_client = False
61+ elif bqstorage_client is None :
5362bqstorage_client = client ._ensure_bqstorage_client ()
5463self ._owns_bqstorage_client = bqstorage_client is not None
5564else :
@@ -95,7 +104,7 @@ def cursor(self):
95104return new_cursor
96105
97106
98- def connect (client = None ,bqstorage_client = None ):
107+ def connect (client = None ,bqstorage_client = None , prefer_bqstorage_client = True ):
99108"""Construct a DB-API connection to Google BigQuery.
100109
101110 Args:
@@ -108,11 +117,12 @@ def connect(client=None, bqstorage_client=None):
108117 A client that uses the faster BigQuery Storage API to fetch rows from
109118 BigQuery. If not passed, it is created using the same credentials
110119 as ``client`` (provided that BigQuery Storage dependencies are installed).
111-
112- If both clients are available, ``bqstorage_client`` is used for
113- fetching query results.
120+ prefer_bqstorage_client (Optional[bool]):
121+ Prefer the BigQuery Storage client over the REST client. If Storage
122+ client isn't available, fall back to the REST client. Defaults to
123+ ``True``.
114124
115125 Returns:
116126 google.cloud.bigquery.dbapi.Connection: A new DB-API connection to BigQuery.
117127 """
118- return Connection (client ,bqstorage_client )
128+ return Connection (client ,bqstorage_client , prefer_bqstorage_client )