@@ -1690,50 +1690,6 @@ def test_dbapi_fetchall(self):
16901690 row_tuples = [r .values () for r in rows ]
16911691 self .assertEqual (row_tuples , [(1 , 2 ), (3 , 4 ), (5 , 6 )])
16921692
1693- @unittest .skipIf (
1694- bigquery_storage_v1 is None , "Requires `google-cloud-bigquery-storage`"
1695- )
1696- def test_dbapi_fetch_w_bqstorage_client_small_result_set (self ):
1697- bqstorage_client = bigquery_storage_v1 .BigQueryReadClient (
1698- credentials = Config .CLIENT ._credentials
1699- )
1700- cursor = dbapi .connect (Config .CLIENT , bqstorage_client ).cursor ()
1701-
1702- # Reading small result sets causes an issue with BQ storage client,
1703- # and the DB API should transparently fall back to the default client.
1704- cursor .execute (
1705- """
1706- SELECT id, `by`, time_ts
1707- FROM `bigquery-public-data.hacker_news.comments`
1708- ORDER BY `id` ASC
1709- LIMIT 10
1710- """
1711- )
1712-
1713- result_rows = [cursor .fetchone (), cursor .fetchone (), cursor .fetchone ()]
1714-
1715- field_name = operator .itemgetter (0 )
1716- fetched_data = [sorted (row .items (), key = field_name ) for row in result_rows ]
1717-
1718- expected_data = [
1719- [
1720- ("by" , "sama" ),
1721- ("id" , 15 ),
1722- ("time_ts" , datetime .datetime (2006 , 10 , 9 , 19 , 51 , 1 , tzinfo = UTC )),
1723- ],
1724- [
1725- ("by" , "pg" ),
1726- ("id" , 17 ),
1727- ("time_ts" , datetime .datetime (2006 , 10 , 9 , 19 , 52 , 45 , tzinfo = UTC )),
1728- ],
1729- [
1730- ("by" , "pg" ),
1731- ("id" , 22 ),
1732- ("time_ts" , datetime .datetime (2006 , 10 , 10 , 2 , 18 , 22 , tzinfo = UTC )),
1733- ],
1734- ]
1735- self .assertEqual (fetched_data , expected_data )
1736-
17371693 @unittest .skipIf (
17381694 bigquery_storage_v1 is None , "Requires `google-cloud-bigquery-storage`"
17391695 )
@@ -1744,10 +1700,6 @@ def test_dbapi_fetch_w_bqstorage_client_large_result_set(self):
17441700 )
17451701 cursor = dbapi .connect (Config .CLIENT , bqstorage_client ).cursor ()
17461702
1747- # Pick a large enough LIMIT value to assure that the fallback to the
1748- # default client is not needed due to the result set being too small
1749- # (a known issue that causes problems when reading such result sets with
1750- # BQ storage client).
17511703 cursor .execute (
17521704 """
17531705 SELECT id, `by`, time_ts
@@ -1794,10 +1746,6 @@ def test_dbapi_fetch_w_bqstorage_client_v1beta1_large_result_set(self):
17941746 )
17951747 cursor = dbapi .connect (Config .CLIENT , bqstorage_client ).cursor ()
17961748
1797- # Pick a large enouhg LIMIT value to assure that the fallback to the
1798- # default client is not needed due to the result set being too small
1799- # (a known issue that causes problems when reding such result sets with
1800- # BQ storage client).
18011749 cursor .execute (
18021750 """
18031751 SELECT id, `by`, time_ts
@@ -1845,10 +1793,6 @@ def test_dbapi_connection_does_not_leak_sockets(self):
18451793 connection = dbapi .connect ()
18461794 cursor = connection .cursor ()
18471795
1848- # Pick a large enough LIMIT value to assure that the fallback to the
1849- # default client is not needed due to the result set being too small
1850- # (a known issue that causes problems when reding such result sets with
1851- # BQ storage client).
18521796 cursor .execute (
18531797 """
18541798 SELECT id, `by`, time_ts
@@ -2272,9 +2216,6 @@ def test_query_results_to_dataframe(self):
22722216 bigquery_storage_v1 is None , "Requires `google-cloud-bigquery-storage`"
22732217 )
22742218 def test_query_results_to_dataframe_w_bqstorage (self ):
2275- dest_dataset = self .temp_dataset (_make_dataset_id ("bqstorage_to_dataframe_" ))
2276- dest_ref = dest_dataset .table ("query_results" )
2277-
22782219 query = """
22792220 SELECT id, author, time_ts, dead
22802221 FROM `bigquery-public-data.hacker_news.comments`
@@ -2285,50 +2226,29 @@ def test_query_results_to_dataframe_w_bqstorage(self):
22852226 credentials = Config .CLIENT ._credentials
22862227 )
22872228
2288- job_configs = (
2289- # There is a known issue reading small anonymous query result
2290- # tables with the BQ Storage API. Writing to a destination
2291- # table works around this issue.
2292- bigquery .QueryJobConfig (
2293- destination = dest_ref , write_disposition = "WRITE_TRUNCATE"
2294- ),
2295- # Check that the client is able to work around the issue with
2296- # reading small anonymous query result tables by falling back to
2297- # the tabledata.list API.
2298- None ,
2299- )
2300-
2301- for job_config in job_configs :
2302- df = (
2303- Config .CLIENT .query (query , job_config = job_config )
2304- .result ()
2305- .to_dataframe (bqstorage_client )
2306- )
2229+ df = Config .CLIENT .query (query ).result ().to_dataframe (bqstorage_client )
23072230
2308- self .assertIsInstance (df , pandas .DataFrame )
2309- self .assertEqual (len (df ), 10 ) # verify the number of rows
2310- column_names = ["id" , "author" , "time_ts" , "dead" ]
2311- self .assertEqual (list (df ), column_names )
2312- exp_datatypes = {
2313- "id" : int ,
2314- "author" : six .text_type ,
2315- "time_ts" : pandas .Timestamp ,
2316- "dead" : bool ,
2317- }
2318- for index , row in df .iterrows ():
2319- for col in column_names :
2320- # all the schema fields are nullable, so None is acceptable
2321- if not row [col ] is None :
2322- self .assertIsInstance (row [col ], exp_datatypes [col ])
2231+ self .assertIsInstance (df , pandas .DataFrame )
2232+ self .assertEqual (len (df ), 10 ) # verify the number of rows
2233+ column_names = ["id" , "author" , "time_ts" , "dead" ]
2234+ self .assertEqual (list (df ), column_names )
2235+ exp_datatypes = {
2236+ "id" : int ,
2237+ "author" : six .text_type ,
2238+ "time_ts" : pandas .Timestamp ,
2239+ "dead" : bool ,
2240+ }
2241+ for index , row in df .iterrows ():
2242+ for col in column_names :
2243+ # all the schema fields are nullable, so None is acceptable
2244+ if not row [col ] is None :
2245+ self .assertIsInstance (row [col ], exp_datatypes [col ])
23232246
23242247 @unittest .skipIf (pandas is None , "Requires `pandas`" )
23252248 @unittest .skipIf (
23262249 bigquery_storage_v1beta1 is None , "Requires `google-cloud-bigquery-storage`"
23272250 )
23282251 def test_query_results_to_dataframe_w_bqstorage_v1beta1 (self ):
2329- dest_dataset = self .temp_dataset (_make_dataset_id ("bqstorage_to_dataframe_" ))
2330- dest_ref = dest_dataset .table ("query_results" )
2331-
23322252 query = """
23332253 SELECT id, author, time_ts, dead
23342254 FROM `bigquery-public-data.hacker_news.comments`
@@ -2339,41 +2259,23 @@ def test_query_results_to_dataframe_w_bqstorage_v1beta1(self):
23392259 credentials = Config .CLIENT ._credentials
23402260 )
23412261
2342- job_configs = (
2343- # There is a known issue reading small anonymous query result
2344- # tables with the BQ Storage API. Writing to a destination
2345- # table works around this issue.
2346- bigquery .QueryJobConfig (
2347- destination = dest_ref , write_disposition = "WRITE_TRUNCATE"
2348- ),
2349- # Check that the client is able to work around the issue with
2350- # reading small anonymous query result tables by falling back to
2351- # the tabledata.list API.
2352- None ,
2353- )
2354-
2355- for job_config in job_configs :
2356- df = (
2357- Config .CLIENT .query (query , job_config = job_config )
2358- .result ()
2359- .to_dataframe (bqstorage_client )
2360- )
2262+ df = Config .CLIENT .query (query ).result ().to_dataframe (bqstorage_client )
23612263
2362- self .assertIsInstance (df , pandas .DataFrame )
2363- self .assertEqual (len (df ), 10 ) # verify the number of rows
2364- column_names = ["id" , "author" , "time_ts" , "dead" ]
2365- self .assertEqual (list (df ), column_names )
2366- exp_datatypes = {
2367- "id" : int ,
2368- "author" : six .text_type ,
2369- "time_ts" : pandas .Timestamp ,
2370- "dead" : bool ,
2371- }
2372- for index , row in df .iterrows ():
2373- for col in column_names :
2374- # all the schema fields are nullable, so None is acceptable
2375- if not row [col ] is None :
2376- self .assertIsInstance (row [col ], exp_datatypes [col ])
2264+ self .assertIsInstance (df , pandas .DataFrame )
2265+ self .assertEqual (len (df ), 10 ) # verify the number of rows
2266+ column_names = ["id" , "author" , "time_ts" , "dead" ]
2267+ self .assertEqual (list (df ), column_names )
2268+ exp_datatypes = {
2269+ "id" : int ,
2270+ "author" : six .text_type ,
2271+ "time_ts" : pandas .Timestamp ,
2272+ "dead" : bool ,
2273+ }
2274+ for index , row in df .iterrows ():
2275+ for col in column_names :
2276+ # all the schema fields are nullable, so None is acceptable
2277+ if not row [col ] is None :
2278+ self .assertIsInstance (row [col ], exp_datatypes [col ])
23772279
23782280 @unittest .skipIf (pandas is None , "Requires `pandas`" )
23792281 def test_insert_rows_from_dataframe (self ):
0 commit comments