|
3 | 3 | from __future__ import absolute_import |
4 | 4 | from __future__ import unicode_literals |
5 | 5 |
|
| 6 | +import re |
| 7 | +import warnings |
| 8 | +from packaging.version import Version, parse as parse_version |
| 9 | + |
6 | 10 | from google import auth |
7 | | -from google.cloud import bigquery, bigquery_storage_v1beta1 |
8 | | -from google.cloud.bigquery import dbapi, QueryJobConfig |
| 11 | +from google.cloud import bigquery |
| 12 | + |
| 13 | +try: |
| 14 | + from google.cloud import bigquery_storage_v1 |
| 15 | +except ImportError: |
| 16 | + pass |
| 17 | + |
| 18 | +from google.cloud.bigquery import dbapi |
9 | 19 | from google.cloud.bigquery.schema import SchemaField |
10 | | -from google.cloud.bigquery.table import EncryptionConfiguration |
11 | | -from google.cloud.bigquery.dataset import DatasetReference |
12 | 20 | from google.oauth2 import service_account |
13 | 21 | from google.api_core.exceptions import NotFound |
14 | 22 | from sqlalchemy.exc import NoSuchTableError |
|
18 | 26 | from sqlalchemy.engine.base import Engine |
19 | 27 | from sqlalchemy.sql.schema import Column |
20 | 28 | from sqlalchemy.sql import elements |
21 | | -import re |
22 | 29 |
|
23 | 30 | from .parse_url import parse_url |
24 | 31 |
|
@@ -342,11 +349,19 @@ def create_connect_args(self, url): |
342 | 349 | default_query_job_config=default_query_job_config |
343 | 350 | ) |
344 | 351 |
|
345 | | - storage_client = None |
| 352 | + clients = [client] |
| 353 | + |
346 | 354 | if use_bqstorage_api: |
347 | | - storage_client = bigquery_storage_v1beta1.BigQueryStorageClient(credentials=credentials) |
| 355 | + if parse_version(bigquery.__version__) >= Version("1.26.0"): |
| 356 | + try: |
| 357 | + storage_client = bigquery_storage_v1.BigQueryReadClient(credentials=credentials) |
| 358 | + clients.append(storage_client) |
| 359 | + except NameError: |
| 360 | + warnings.warn("It is not possible to use the bqstorage api without installing the bqstorage extra requirement") |
| 361 | + else: |
| 362 | + warnings.warn('It is not possible to use the bqstorage api with google-cloud-bigquery < 1.26.0') |
348 | 363 |
|
349 | | - return ([client, storage_client], {}) |
| 364 | + return (clients, {}) |
350 | 365 |
|
351 | 366 | def _json_deserializer(self, row): |
352 | 367 | """JSON deserializer for RECORD types. |
|
0 commit comments