@@ -35,12 +35,18 @@ class Connection(object):
35
35
A client that uses the faster BigQuery Storage API to fetch rows from
36
36
BigQuery. If not passed, it is created using the same credentials
37
37
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``.
41
42
"""
42
43
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
+ ):
44
50
if client is None :
45
51
client = bigquery .Client ()
46
52
self ._owns_client = True
@@ -49,7 +55,10 @@ def __init__(self, client=None, bqstorage_client=None):
49
55
50
56
# A warning is already raised by the BQ Storage client factory factory if
51
57
# 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 :
53
62
bqstorage_client = client ._ensure_bqstorage_client ()
54
63
self ._owns_bqstorage_client = bqstorage_client is not None
55
64
else :
@@ -95,7 +104,7 @@ def cursor(self):
95
104
return new_cursor
96
105
97
106
98
- def connect (client = None , bqstorage_client = None ):
107
+ def connect (client = None , bqstorage_client = None , prefer_bqstorage_client = True ):
99
108
"""Construct a DB-API connection to Google BigQuery.
100
109
101
110
Args:
@@ -108,11 +117,12 @@ def connect(client=None, bqstorage_client=None):
108
117
A client that uses the faster BigQuery Storage API to fetch rows from
109
118
BigQuery. If not passed, it is created using the same credentials
110
119
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``.
114
124
115
125
Returns:
116
126
google.cloud.bigquery.dbapi.Connection: A new DB-API connection to BigQuery.
117
127
"""
118
- return Connection (client , bqstorage_client )
128
+ return Connection (client , bqstorage_client , prefer_bqstorage_client )
0 commit comments