1414
1515import itertools
1616import json
17+ import logging
1718import time
1819import unittest
1920import warnings
@@ -1445,8 +1446,16 @@ def _class_under_test(self):
14451446 return RowIterator
14461447
14471448 def _make_one (
1448- self , client = None , api_request = None , path = None , schema = None , ** kwargs
1449+ self ,
1450+ client = None ,
1451+ api_request = None ,
1452+ path = None ,
1453+ schema = None ,
1454+ table = None ,
1455+ ** kwargs
14491456 ):
1457+ from google .cloud .bigquery .table import TableReference
1458+
14501459 if client is None :
14511460 client = _mock_client ()
14521461
@@ -1459,7 +1468,12 @@ def _make_one(
14591468 if schema is None :
14601469 schema = []
14611470
1462- return self ._class_under_test ()(client , api_request , path , schema , ** kwargs )
1471+ if table is None :
1472+ table = TableReference .from_string ("my-project.my_dataset.my_table" )
1473+
1474+ return self ._class_under_test ()(
1475+ client , api_request , path , schema , table = table , ** kwargs
1476+ )
14631477
14641478 def test_constructor (self ):
14651479 from google .cloud .bigquery .table import _item_to_row
@@ -2071,16 +2085,32 @@ def test_to_dataframe_w_empty_results(self):
20712085 SchemaField ("name" , "STRING" , mode = "REQUIRED" ),
20722086 SchemaField ("age" , "INTEGER" , mode = "REQUIRED" ),
20732087 ]
2074- path = "/foo"
20752088 api_request = mock .Mock (return_value = {"rows" : []})
2076- row_iterator = self ._make_one (_mock_client (), api_request , path , schema )
2089+ row_iterator = self ._make_one (_mock_client (), api_request , schema = schema )
20772090
20782091 df = row_iterator .to_dataframe ()
20792092
20802093 self .assertIsInstance (df , pandas .DataFrame )
20812094 self .assertEqual (len (df ), 0 ) # verify the number of rows
20822095 self .assertEqual (list (df ), ["name" , "age" ]) # verify the column names
20832096
2097+ @unittest .skipIf (pandas is None , "Requires `pandas`" )
2098+ def test_to_dataframe_logs_tabledata_list (self ):
2099+ from google .cloud .bigquery .table import Table
2100+
2101+ mock_logger = mock .create_autospec (logging .Logger )
2102+ api_request = mock .Mock (return_value = {"rows" : []})
2103+ row_iterator = self ._make_one (
2104+ _mock_client (), api_request , table = Table ("debug-proj.debug_dset.debug_tbl" )
2105+ )
2106+
2107+ with mock .patch ("google.cloud.bigquery.table._LOGGER" , mock_logger ):
2108+ row_iterator .to_dataframe ()
2109+
2110+ mock_logger .debug .assert_any_call (
2111+ "Started reading table 'debug-proj.debug_dset.debug_tbl' with tabledata.list."
2112+ )
2113+
20842114 @unittest .skipIf (pandas is None , "Requires `pandas`" )
20852115 def test_to_dataframe_w_various_types_nullable (self ):
20862116 import datetime
@@ -2191,23 +2221,13 @@ def test_to_dataframe_w_bqstorage_no_streams(self):
21912221 bigquery_storage_v1beta1 .BigQueryStorageClient
21922222 )
21932223 session = bigquery_storage_v1beta1 .types .ReadSession ()
2194- session .avro_schema .schema = json .dumps (
2195- {
2196- "fields" : [
2197- {"name" : "colA" },
2198- # Not alphabetical to test column order.
2199- {"name" : "colC" },
2200- {"name" : "colB" },
2201- ]
2202- }
2203- )
22042224 bqstorage_client .create_read_session .return_value = session
22052225
22062226 row_iterator = mut .RowIterator (
22072227 _mock_client (),
2208- None , # api_request: ignored
2209- None , # path: ignored
2210- [
2228+ api_request = None ,
2229+ path = None ,
2230+ schema = [
22112231 schema .SchemaField ("colA" , "IGNORED" ),
22122232 schema .SchemaField ("colC" , "IGNORED" ),
22132233 schema .SchemaField ("colB" , "IGNORED" ),
@@ -2220,6 +2240,33 @@ def test_to_dataframe_w_bqstorage_no_streams(self):
22202240 self .assertEqual (list (got ), column_names )
22212241 self .assertTrue (got .empty )
22222242
2243+ @unittest .skipIf (
2244+ bigquery_storage_v1beta1 is None , "Requires `google-cloud-bigquery-storage`"
2245+ )
2246+ @unittest .skipIf (pandas is None , "Requires `pandas`" )
2247+ @unittest .skipIf (pyarrow is None , "Requires `pyarrow`" )
2248+ def test_to_dataframe_w_bqstorage_logs_session (self ):
2249+ from google .cloud .bigquery .table import Table
2250+
2251+ bqstorage_client = mock .create_autospec (
2252+ bigquery_storage_v1beta1 .BigQueryStorageClient
2253+ )
2254+ session = bigquery_storage_v1beta1 .types .ReadSession ()
2255+ session .name = "projects/test-proj/locations/us/sessions/SOMESESSION"
2256+ bqstorage_client .create_read_session .return_value = session
2257+ mock_logger = mock .create_autospec (logging .Logger )
2258+ row_iterator = self ._make_one (
2259+ _mock_client (), table = Table ("debug-proj.debug_dset.debug_tbl" )
2260+ )
2261+
2262+ with mock .patch ("google.cloud.bigquery._pandas_helpers._LOGGER" , mock_logger ):
2263+ row_iterator .to_dataframe (bqstorage_client = bqstorage_client )
2264+
2265+ mock_logger .debug .assert_any_call (
2266+ "Started reading table 'debug-proj.debug_dset.debug_tbl' "
2267+ "with BQ Storage API session 'projects/test-proj/locations/us/sessions/SOMESESSION'."
2268+ )
2269+
22232270 @unittest .skipIf (pandas is None , "Requires `pandas`" )
22242271 @unittest .skipIf (
22252272 bigquery_storage_v1beta1 is None , "Requires `google-cloud-bigquery-storage`"
0 commit comments