@@ -60,12 +60,13 @@ def print_results(query_results):
6060
6161def query_positional_params (corpus , min_word_count ):
6262 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+ """
6970 query_job = client .run_async_query (
7071 str (uuid .uuid4 ()),
7172 query ,
@@ -74,9 +75,7 @@ def query_positional_params(corpus, min_word_count):
7475 # Set the name to None to use positional parameters (? symbol
7576 # in the query). Note that you cannot mix named and positional
7677 # parameters.
77- None ,
78- 'STRING' ,
79- corpus ),
78+ None , 'STRING' , corpus ),
8079 bigquery .ScalarQueryParameter (None , 'INT64' , min_word_count )))
8180
8281 # Only standard SQL syntax supports parameters in queries.
@@ -91,21 +90,20 @@ def query_positional_params(corpus, min_word_count):
9190
9291def query_named_params (corpus , min_word_count ):
9392 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+ """
100100 query_job = client .run_async_query (
101101 str (uuid .uuid4 ()),
102102 query ,
103103 query_parameters = (
104104 bigquery .ScalarQueryParameter ('corpus' , 'STRING' , corpus ),
105105 bigquery .ScalarQueryParameter (
106- 'min_word_count' ,
107- 'INT64' ,
108- min_word_count )))
106+ 'min_word_count' , 'INT64' , min_word_count )))
109107 query_job .use_legacy_sql = False
110108
111109 # Start the query and wait for the job to complete.
@@ -116,14 +114,15 @@ def query_named_params(corpus, min_word_count):
116114
117115def query_array_params (gender , states ):
118116 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+ """
127126 query_job = client .run_async_query (
128127 str (uuid .uuid4 ()),
129128 query ,
0 commit comments