@@ -1690,50 +1690,6 @@ def test_dbapi_fetchall(self):
1690
1690
row_tuples = [r .values () for r in rows ]
1691
1691
self .assertEqual (row_tuples , [(1 , 2 ), (3 , 4 ), (5 , 6 )])
1692
1692
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
-
1737
1693
@unittest .skipIf (
1738
1694
bigquery_storage_v1 is None , "Requires `google-cloud-bigquery-storage`"
1739
1695
)
@@ -1744,10 +1700,6 @@ def test_dbapi_fetch_w_bqstorage_client_large_result_set(self):
1744
1700
)
1745
1701
cursor = dbapi .connect (Config .CLIENT , bqstorage_client ).cursor ()
1746
1702
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).
1751
1703
cursor .execute (
1752
1704
"""
1753
1705
SELECT id, `by`, time_ts
@@ -1794,10 +1746,6 @@ def test_dbapi_fetch_w_bqstorage_client_v1beta1_large_result_set(self):
1794
1746
)
1795
1747
cursor = dbapi .connect (Config .CLIENT , bqstorage_client ).cursor ()
1796
1748
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).
1801
1749
cursor .execute (
1802
1750
"""
1803
1751
SELECT id, `by`, time_ts
@@ -1845,10 +1793,6 @@ def test_dbapi_connection_does_not_leak_sockets(self):
1845
1793
connection = dbapi .connect ()
1846
1794
cursor = connection .cursor ()
1847
1795
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).
1852
1796
cursor .execute (
1853
1797
"""
1854
1798
SELECT id, `by`, time_ts
@@ -2272,9 +2216,6 @@ def test_query_results_to_dataframe(self):
2272
2216
bigquery_storage_v1 is None , "Requires `google-cloud-bigquery-storage`"
2273
2217
)
2274
2218
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
-
2278
2219
query = """
2279
2220
SELECT id, author, time_ts, dead
2280
2221
FROM `bigquery-public-data.hacker_news.comments`
@@ -2285,50 +2226,29 @@ def test_query_results_to_dataframe_w_bqstorage(self):
2285
2226
credentials = Config .CLIENT ._credentials
2286
2227
)
2287
2228
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 )
2307
2230
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 ])
2323
2246
2324
2247
@unittest .skipIf (pandas is None , "Requires `pandas`" )
2325
2248
@unittest .skipIf (
2326
2249
bigquery_storage_v1beta1 is None , "Requires `google-cloud-bigquery-storage`"
2327
2250
)
2328
2251
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
-
2332
2252
query = """
2333
2253
SELECT id, author, time_ts, dead
2334
2254
FROM `bigquery-public-data.hacker_news.comments`
@@ -2339,41 +2259,23 @@ def test_query_results_to_dataframe_w_bqstorage_v1beta1(self):
2339
2259
credentials = Config .CLIENT ._credentials
2340
2260
)
2341
2261
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 )
2361
2263
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 ])
2377
2279
2378
2280
@unittest .skipIf (pandas is None , "Requires `pandas`" )
2379
2281
def test_insert_rows_from_dataframe (self ):
0 commit comments