1
1
# -*- coding: utf-8 -*-
2
2
3
3
import sys
4
- import uuid
5
4
from datetime import datetime
6
5
7
- import google .oauth2 .service_account
8
6
import numpy as np
9
7
import pandas
10
8
import pandas .api .types
@@ -28,76 +26,6 @@ def test_imports():
28
26
gbq ._test_google_api_imports ()
29
27
30
28
31
- @pytest .fixture (params = ["env" ])
32
- def project (request , project_id ):
33
- if request .param == "env" :
34
- return project_id
35
- elif request .param == "none" :
36
- return None
37
-
38
-
39
- @pytest .fixture ()
40
- def credentials (private_key_path ):
41
- return google .oauth2 .service_account .Credentials .from_service_account_file (
42
- private_key_path
43
- )
44
-
45
-
46
- @pytest .fixture ()
47
- def gbq_connector (project , credentials ):
48
- return gbq .GbqConnector (project , credentials = credentials )
49
-
50
-
51
- @pytest .fixture ()
52
- def random_dataset (bigquery_client , random_dataset_id ):
53
- from google .cloud import bigquery
54
-
55
- dataset_ref = bigquery_client .dataset (random_dataset_id )
56
- dataset = bigquery .Dataset (dataset_ref )
57
- bigquery_client .create_dataset (dataset )
58
- return dataset
59
-
60
-
61
- @pytest .fixture ()
62
- def tokyo_dataset (bigquery_client , random_dataset_id ):
63
- from google .cloud import bigquery
64
-
65
- dataset_ref = bigquery_client .dataset (random_dataset_id )
66
- dataset = bigquery .Dataset (dataset_ref )
67
- dataset .location = "asia-northeast1"
68
- bigquery_client .create_dataset (dataset )
69
- return random_dataset_id
70
-
71
-
72
- @pytest .fixture ()
73
- def tokyo_table (bigquery_client , tokyo_dataset ):
74
- table_id = "tokyo_table"
75
- # Create a random table using DDL.
76
- # https://github.com/GoogleCloudPlatform/golang-samples/blob/2ab2c6b79a1ea3d71d8f91609b57a8fbde07ae5d/bigquery/snippets/snippet.go#L739
77
- bigquery_client .query (
78
- """CREATE TABLE {}.{}
79
- AS SELECT
80
- 2000 + CAST(18 * RAND() as INT64) as year,
81
- IF(RAND() > 0.5,"foo","bar") as token
82
- FROM UNNEST(GENERATE_ARRAY(0,5,1)) as r
83
- """ .format (
84
- tokyo_dataset , table_id
85
- ),
86
- location = "asia-northeast1" ,
87
- ).result ()
88
- return table_id
89
-
90
-
91
- @pytest .fixture ()
92
- def gbq_dataset (project , credentials ):
93
- return gbq ._Dataset (project , credentials = credentials )
94
-
95
-
96
- @pytest .fixture ()
97
- def gbq_table (project , credentials , random_dataset_id ):
98
- return gbq ._Table (project , random_dataset_id , credentials = credentials )
99
-
100
-
101
29
def make_mixed_dataframe_v2 (test_size ):
102
30
# create df to test for all BQ datatypes except RECORD
103
31
bools = np .random .randint (2 , size = (1 , test_size )).astype (bool )
@@ -898,43 +826,6 @@ def test_tokyo(self, tokyo_dataset, tokyo_table, project_id):
898
826
assert df ["max_year" ][0 ] >= 2000
899
827
900
828
901
- @pytest .mark .slow (reason = "Large query for BQ Storage API tests." )
902
- def test_read_gbq_w_bqstorage_api (credentials , random_dataset ):
903
- pytest .importorskip ("google.cloud.bigquery_storage" )
904
- df = gbq .read_gbq (
905
- """
906
- SELECT
907
- total_amount,
908
- passenger_count,
909
- trip_distance
910
- FROM `bigquery-public-data.new_york_taxi_trips.tlc_green_trips_2014`
911
- -- Select non-null rows for no-copy conversion from Arrow to pandas.
912
- WHERE total_amount IS NOT NULL
913
- AND passenger_count IS NOT NULL
914
- AND trip_distance IS NOT NULL
915
- LIMIT 10000000
916
- """ ,
917
- use_bqstorage_api = True ,
918
- credentials = credentials ,
919
- configuration = {
920
- "query" : {
921
- "destinationTable" : {
922
- "projectId" : random_dataset .project ,
923
- "datasetId" : random_dataset .dataset_id ,
924
- "tableId" : "" .join (
925
- [
926
- "test_read_gbq_w_bqstorage_api_" ,
927
- str (uuid .uuid4 ()).replace ("-" , "_" ),
928
- ]
929
- ),
930
- },
931
- "writeDisposition" : "WRITE_TRUNCATE" ,
932
- }
933
- },
934
- )
935
- assert len (df ) == 10000000
936
-
937
-
938
829
class TestToGBQIntegration (object ):
939
830
@pytest .fixture (autouse = True , scope = "function" )
940
831
def setup (self , project , credentials , random_dataset_id ):
0 commit comments