File tree Expand file tree Collapse file tree 3 files changed +19
-12
lines changed
Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 1+ # [START bigquery_simple_app_pkgs]
12google-cloud-bigquery == 0.28.0
3+ # [END bigquery_simple_app_pkgs]
24google-auth-oauthlib == 0.2.0
35pytz == 2017.3
Original file line number Diff line number Diff line change 1616
1717"""Simple application that performs a query with BigQuery."""
1818# [START all]
19- # [START create_client ]
19+ # [START bigquery_simple_app_deps ]
2020from google .cloud import bigquery
21+ # [END bigquery_simple_app_deps]
2122
2223
23- def query_shakespeare ():
24+ def query_stackoverflow ():
25+ # [START create_client]
2426 client = bigquery .Client ()
2527 # [END create_client]
2628 # [START run_query]
2729 query_job = client .query ("""
28- #standardSQL
29- SELECT corpus AS title, COUNT(*) AS unique_words
30- FROM `bigquery-public-data.samples.shakespeare`
31- GROUP BY title
32- ORDER BY unique_words DESC
30+ SELECT
31+ CONCAT(
32+ 'https://stackoverflow.com/questions/',
33+ CAST(id as STRING)) as url,
34+ view_count
35+ FROM `bigquery-public-data.stackoverflow.posts_questions`
36+ WHERE tags like '%google-bigquery%'
37+ ORDER BY view_count DESC
3338 LIMIT 10""" )
3439
3540 results = query_job .result () # Waits for job to complete.
3641 # [END run_query]
3742
3843 # [START print_results]
3944 for row in results :
40- print ("{}: {}" .format (row .title , row .unique_words ))
45+ print ("{} : {} views " .format (row .url , row .view_count ))
4146 # [END print_results]
4247
4348
4449if __name__ == '__main__' :
45- query_shakespeare ()
50+ query_stackoverflow ()
4651# [END all]
Original file line number Diff line number Diff line change 1515import simple_app
1616
1717
18- def test_query_shakespeare (capsys ):
19- simple_app .query_shakespeare ()
18+ def test_query_stackoverflow (capsys ):
19+ simple_app .query_stackoverflow ()
2020 out , _ = capsys .readouterr ()
21- assert 'hamlet ' in out
21+ assert 'views ' in out
You can’t perform that action at this time.
0 commit comments