Query#

Define API Queries.

class google.cloud.bigquery.query.QueryResults(query, client, udf_resources=())[source]#

Bases: object

Synchronous job: query tables.

Parameters:
cache_hit#

Query results served from cache.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#cacheHit

Return type:boolean or NoneType
Returns:True if the query results were served from cache (None until set by the server).
complete#

Server completed query.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#jobComplete

Return type:boolean or NoneType
Returns:True if the query completed on the server (None until set by the server).
default_dataset#

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#defaultDataset

dry_run#

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#dryRun

errors#

Errors generated by the query.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#errors

Return type:list of mapping, or NoneType
Returns:Mappings describing errors generated on the server (None until set by the server).
fetch_data(max_results=None, page_token=None, start_index=None, timeout_ms=None, client=None)[source]#

API call: fetch a page of query result data via a GET request

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/getQueryResults

Parameters:
  • max_results (integer or NoneType) – maximum number of rows to return.
  • page_token (string or NoneType) – token representing a cursor into the table’s rows.
  • start_index (integer or NoneType) – zero-based index of starting row
  • timeout_ms (integer or NoneType) – timeout, in milliseconds, to wait for query to complete
  • client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.
Return type:

tuple

Returns:

(row_data, total_rows, page_token), where row_data is a list of tuples, one per result row, containing only the values; total_rows is a count of the total number of rows in the table; and page_token is an opaque string which can be used to fetch the next batch of rows (None if no further batches can be fetched).

Raises:

ValueError if the query has not yet been executed.

job#

Job instance used to run the query.

Return type:google.cloud.bigquery.job.QueryJob, or NoneType
Returns:Job instance used to run the query (None until jobReference property is set by the server).
max_results#

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#maxResults

name#

Job name, generated by the back-end.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#jobReference

Return type:list of mapping, or NoneType
Returns:Mappings describing errors generated on the server (None until set by the server).
page_token#

Token for fetching next bach of results.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#pageToken

Return type:string, or NoneType
Returns:Token generated on the server (None until set by the server).
preserve_nulls#

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#preserveNulls

project#

Project bound to the job.

Return type:string
Returns:the project (derived from the client).
rows#

Query results.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#rows

Return type:list of tuples of row values, or NoneType
Returns:fields describing the schema (None until set by the server).
run(client=None)[source]#

API call: run the query via a POST request

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current dataset.
schema#

Schema for query results.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#schema

Return type:list of SchemaField, or NoneType
Returns:fields describing the schema (None until set by the server).
timeout_ms#

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#timeoutMs

total_bytes_processed#

Total number of bytes processed by the query.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#totalBytesProcessed

Return type:integer, or NoneType
Returns:Count generated on the server (None until set by the server).
total_rows#

Total number of rows returned by the query.

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#totalRows

Return type:integer, or NoneType
Returns:Count generated on the server (None until set by the server).
use_legacy_sql#

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#useLegacySql

use_query_cache#

See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#useQueryCache