File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -2225,6 +2225,32 @@ def test_client_query_legacy_sql(client):
22252225 # [END bigquery_query_legacy]
22262226
22272227
2228+ def test_client_query_total_rows (client , capsys ):
2229+ """Run a query and just check for how many rows."""
2230+ # [START bigquery_query_total_rows]
2231+ # from google.cloud import bigquery
2232+ # client = bigquery.Client()
2233+
2234+ query = (
2235+ "SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` "
2236+ 'WHERE state = "TX" '
2237+ "LIMIT 100"
2238+ )
2239+ query_job = client .query (
2240+ query ,
2241+ # Location must match that of the dataset(s) referenced in the query.
2242+ location = "US" ,
2243+ ) # API request - starts the query
2244+
2245+ results = query_job .result () # Waits for query to complete.
2246+ next (iter (results )) # Fetch the first page of results, which contains total_rows.
2247+ print ("Got {} rows." .format (results .total_rows ))
2248+ # [END bigquery_query_total_rows]
2249+
2250+ out , _ = capsys .readouterr ()
2251+ assert "Got 100 rows." in out
2252+
2253+
22282254def test_manage_job (client ):
22292255 sql = """
22302256 SELECT corpus
You can’t perform that action at this time.
0 commit comments