Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample for fetching total_rows from query results. #7217

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 an just check for how many rows."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/and/

# [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))
# [START bigquery_query_total_rows]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

END?


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


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