query_builder

bigquery.query_builder.render_query(dataset, tables, select=None, conditions=None, groupings=None, having=None, order_by=None)

Render a query that will run over the given tables using the specified parameters.

Parameters:

dataset : str

The BigQuery dataset to query data from

tables : Union[dict, list]

The table in dataset to query.

select : dict, optional

The keys function as column names and the values function as options to apply to the select field such as alias and format. For example, select[‘start_time’] might have the form {‘alias’: ‘StartTime’, ‘format’: ‘INTEGER-FORMAT_UTC_USEC’}, which would be represented as ‘SEC_TO_TIMESTAMP(INTEGER(start_time)) as StartTime’ in a query. Pass None to seoect all.

conditions : list, optional

a list of dict objects to filter results by. Each dict should have the keys ‘field’, ‘type’, and ‘comparators’. The first two map to strings representing the field (e.g. ‘foo’) and type (e.g. ‘FLOAT’). ‘comparators’ maps to another dict containing the keys ‘condition’, ‘negate’, and ‘value’. If ‘comparators’ = {‘condition’: ‘>=’, ‘negate’: False, ‘value’: 1}, this example will be rdnered as ‘foo >= FLOAT(‘1’)’ in the query. list of field names to group by

order_by : dict, optional

Keys = {‘field’, ‘direction’}. dict should be formatted as {‘field’:’TimeStamp, ‘direction’:’desc’} or similar

Returns:

str

A rendered query