diff --git a/bigquery/google/cloud/bigquery/table.py b/bigquery/google/cloud/bigquery/table.py index 4584e964894e..38c26871502c 100644 --- a/bigquery/google/cloud/bigquery/table.py +++ b/bigquery/google/cloud/bigquery/table.py @@ -17,6 +17,7 @@ from __future__ import absolute_import import collections +import concurrent.futures import copy import datetime import json @@ -25,6 +26,11 @@ import six +try: + from google.cloud import bigquery_storage_v1beta1 +except ImportError: # pragma: NO COVER + bigquery_storage_v1beta1 = None + try: import pandas except ImportError: # pragma: NO COVER @@ -46,6 +52,10 @@ from google.cloud.bigquery.external_config import ExternalConfig +_NO_BQSTORAGE_ERROR = ( + "The google-cloud-bigquery-storage library is not installed, " + "please install google-cloud-bigquery-storage to use bqstorage features." +) _NO_PANDAS_ERROR = ( "The pandas library is not installed, please install " "pandas to use the to_dataframe() function." @@ -287,7 +297,8 @@ def to_bqstorage(self): google.cloud.bigquery_storage_v1beta1.types.TableReference: A reference to this table in the BigQuery Storage API. """ - from google.cloud import bigquery_storage_v1beta1 + if bigquery_storage_v1beta1 is None: + raise ValueError(_NO_BQSTORAGE_ERROR) table_ref = bigquery_storage_v1beta1.types.TableReference() table_ref.project_id = self._project @@ -1391,8 +1402,8 @@ def _to_dataframe_bqstorage_stream( def _to_dataframe_bqstorage(self, bqstorage_client, dtypes): """Use (faster, but billable) BQ Storage API to construct DataFrame.""" - import concurrent.futures - from google.cloud import bigquery_storage_v1beta1 + if bigquery_storage_v1beta1 is None: + raise ValueError(_NO_BQSTORAGE_ERROR) if "$" in self._table.table_id: raise ValueError(