Skip to content

Commit

Permalink
Add sample for fetching total_rows from query results. (#7217)
Browse files Browse the repository at this point in the history
* Add sample for fetching total_rows from query results.

* Copypasta
  • Loading branch information
tswast authored Jan 30, 2019
1 parent 5183966 commit 51c97cd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bigquery/docs/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,32 @@ def test_client_query_legacy_sql(client):
# [END bigquery_query_legacy]


def test_client_query_total_rows(client, capsys):
"""Run a query and just check for how many rows."""
# [START bigquery_query_total_rows]
# from google.cloud import bigquery
# client = bigquery.Client()

query = (
"SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` "
'WHERE state = "TX" '
"LIMIT 100"
)
query_job = client.query(
query,
# Location must match that of the dataset(s) referenced in the query.
location="US",
) # API request - starts the query

results = query_job.result() # Waits for query to complete.
next(iter(results)) # Fetch the first page of results, which contains total_rows.
print("Got {} rows.".format(results.total_rows))
# [END bigquery_query_total_rows]

out, _ = capsys.readouterr()
assert "Got 100 rows." in out


def test_manage_job(client):
sql = """
SELECT corpus
Expand Down

0 comments on commit 51c97cd

Please sign in to comment.