Query#
Define API Queries.
-
class
gcloud.bigquery.query.QueryResults(query, client)[source]# Bases:
objectSynchronous job: query tables.
Parameters: - query (string) – SQL query string
- client (
gcloud.bigquery.client.Client) – A client which holds credentials and project configuration for the dataset (which requires a project).
-
cache_hit# Query results served from cache.
See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#cacheHit
Return type: boolean or NoneTypeReturns: 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 NoneTypeReturns: 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
-
errors# Errors generated by the query.
See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#errors
Return type: list of mapping, or NoneTypeReturns: 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 (
gcloud.bigquery.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current dataset.
Return type: Returns: (row_data, total_rows, page_token), whererow_datais a list of tuples, one per result row, containing only the values;total_rowsis a count of the total number of rows in the table; andpage_tokenis an opaque string which can be used to fetch the next batch of rows (Noneif no further batches can be fetched).Raises: ValueError if the query has not yet been executed.
- max_results (integer or
-
job# Job instance used to run the query.
Return type: gcloud.bigquery.job.QueryJob, orNoneTypeReturns: Job instance used to run the query (None until jobReferenceproperty is set by the server).
-
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 NoneTypeReturns: 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 NoneTypeReturns: 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 NoneTypeReturns: 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 ( gcloud.bigquery.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored 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, orNoneTypeReturns: fields describing the schema (None until set by the server).
-
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 NoneTypeReturns: 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 NoneTypeReturns: Count generated on the server (None until set by the server).
-
use_query_cache# See: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#useQueryCache