Skip to content
Merged
Changes from all commits
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 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