Repository: googleapis/python-bigquery (python)

Issue:
Add a warning message when BigQuery Storage API is not used despite create_bqstorage_client=True
**Is your feature request related to a problem? Please describe.**
This issue is related to the code [here](https://github.com/googleapis/python-bigquery/blob/4f72723f539d35977bc52c5950f6e00889b5c7be/google/cloud/bigquery/table.py). Even when `create_bqstorage_client=True` is specified, the BigQuery Storage API is not used if the BigQuery Storage API module is not found. I think this is not logged, which can confuse users.

**Describe the solution you'd like**
I would like to add a warning message when `create_bqstorage_client=True` is specified, but the BigQuery Storage API is not used at the code [here](https://github.com/googleapis/python-bigquery/blob/4f72723f539d35977bc52c5950f6e00889b5c7be/google/cloud/bigquery/table.py#L1726C9-L1727C25).


Pull request:
chore: add warning if storage module not found
Adds a warning message if storage client is not used because module is not found.

Fixes #1931 🦕


Patch:
diff --git a/google/cloud/bigquery/table.py b/google/cloud/bigquery/table.py
index 6ebb0709..57fc0d2b 100644
--- a/google/cloud/bigquery/table.py
+++ b/google/cloud/bigquery/table.py
@@ -1724,6 +1724,10 @@ class RowIterator(HTTPIterator):
         try:
             _versions_helpers.BQ_STORAGE_VERSIONS.try_import(raise_if_error=True)
         except bq_exceptions.BigQueryStorageNotFoundError:
+            warnings.warn(
+                "BigQuery Storage module not found, fetch data with the REST "
+                "endpoint instead."
+            )
             return False
         except bq_exceptions.LegacyBigQueryStorageError as exc:
             warnings.warn(str(exc))


Test patch:
diff --git a/tests/unit/test_table.py b/tests/unit/test_table.py
index fcbba03a..2a49b063 100644
--- a/tests/unit/test_table.py
+++ b/tests/unit/test_table.py
@@ -2360,24 +2360,30 @@ class TestRowIterator(unittest.TestCase):
         )
         self.assertFalse(result)
 
-    def test__should_use_bqstorage_returns_false_if_missing_dependency(self):
+    def test__should_use_bqstorage_returns_false_w_warning_if_missing_dependency(self):
         iterator = self._make_one(first_page_response=None)  # not cached
-
+ 
         def fail_bqstorage_import(name, globals, locals, fromlist, level):
+            """Returns True if bigquery_storage has been imported."""
             # NOTE: *very* simplified, assuming a straightforward absolute import
             return "bigquery_storage" in name or (
                 fromlist is not None and "bigquery_storage" in fromlist
             )
-
+        # maybe_fail_import() returns ImportError if the predicate is True
         no_bqstorage = maybe_fail_import(predicate=fail_bqstorage_import)
 
-        with no_bqstorage:
+        with no_bqstorage, warnings.catch_warnings(record=True) as warned:
             result = iterator._should_use_bqstorage(
                 bqstorage_client=None, create_bqstorage_client=True
             )
 
         self.assertFalse(result)
 
+        matching_warnings = [
+            warning for warning in warned if "Storage module not found" in str(warning)
+        ]
+        assert matching_warnings, "Dependency not found warning not raised."
+
     def test__should_use_bqstorage_returns_false_w_warning_if_obsolete_version(self):
         pytest.importorskip("google.cloud.bigquery_storage")
         iterator = self._make_one(first_page_response=None)  # not cached