@@ -60,12 +60,13 @@ def print_results(query_results):
60
60
61
61
def query_positional_params (corpus , min_word_count ):
62
62
client = bigquery .Client ()
63
- query = """SELECT word, word_count
64
- FROM `bigquery-public-data.samples.shakespeare`
65
- WHERE corpus = ?
66
- AND word_count >= ?
67
- ORDER BY word_count DESC;
68
- """
63
+ query = """
64
+ SELECT word, word_count
65
+ FROM `bigquery-public-data.samples.shakespeare`
66
+ WHERE corpus = ?
67
+ AND word_count >= ?
68
+ ORDER BY word_count DESC;
69
+ """
69
70
query_job = client .run_async_query (
70
71
str (uuid .uuid4 ()),
71
72
query ,
@@ -74,9 +75,7 @@ def query_positional_params(corpus, min_word_count):
74
75
# Set the name to None to use positional parameters (? symbol
75
76
# in the query). Note that you cannot mix named and positional
76
77
# parameters.
77
- None ,
78
- 'STRING' ,
79
- corpus ),
78
+ None , 'STRING' , corpus ),
80
79
bigquery .ScalarQueryParameter (None , 'INT64' , min_word_count )))
81
80
82
81
# Only standard SQL syntax supports parameters in queries.
@@ -91,21 +90,20 @@ def query_positional_params(corpus, min_word_count):
91
90
92
91
def query_named_params (corpus , min_word_count ):
93
92
client = bigquery .Client ()
94
- query = """SELECT word, word_count
95
- FROM `bigquery-public-data.samples.shakespeare`
96
- WHERE corpus = @corpus
97
- AND word_count >= @min_word_count
98
- ORDER BY word_count DESC;
99
- """
93
+ query = """
94
+ SELECT word, word_count
95
+ FROM `bigquery-public-data.samples.shakespeare`
96
+ WHERE corpus = @corpus
97
+ AND word_count >= @min_word_count
98
+ ORDER BY word_count DESC;
99
+ """
100
100
query_job = client .run_async_query (
101
101
str (uuid .uuid4 ()),
102
102
query ,
103
103
query_parameters = (
104
104
bigquery .ScalarQueryParameter ('corpus' , 'STRING' , corpus ),
105
105
bigquery .ScalarQueryParameter (
106
- 'min_word_count' ,
107
- 'INT64' ,
108
- min_word_count )))
106
+ 'min_word_count' , 'INT64' , min_word_count )))
109
107
query_job .use_legacy_sql = False
110
108
111
109
# Start the query and wait for the job to complete.
@@ -116,14 +114,15 @@ def query_named_params(corpus, min_word_count):
116
114
117
115
def query_array_params (gender , states ):
118
116
client = bigquery .Client ()
119
- query = """SELECT name, sum(number) as count
120
- FROM `bigquery-public-data.usa_names.usa_1910_2013`
121
- WHERE gender = @gender
122
- AND state IN UNNEST(@states)
123
- GROUP BY name
124
- ORDER BY count DESC
125
- LIMIT 10;
126
- """
117
+ query = """
118
+ SELECT name, sum(number) as count
119
+ FROM `bigquery-public-data.usa_names.usa_1910_2013`
120
+ WHERE gender = @gender
121
+ AND state IN UNNEST(@states)
122
+ GROUP BY name
123
+ ORDER BY count DESC
124
+ LIMIT 10;
125
+ """
127
126
query_job = client .run_async_query (
128
127
str (uuid .uuid4 ()),
129
128
query ,
0 commit comments