mozanalysis.bq
- class mozanalysis.bq.BigQueryContext(dataset_id, project_id='moz-fx-data-bq-data-science')[source]
Holds a BigQuery client, and some configuration.
- Parameters:
dataset_id (str) – Your BigQuery dataset id.
project_id (str, optional) – Your BigQuery project_id. Defaults to the DS team’s project.
- run_query(sql, results_table=None, replace_tables=False)[source]
Run a query and return the result.
If
results_table
is provided, then save the results into there (or just query from there if it already exists). Returns agoogle.cloud.bigquery.table.RowIterator
- Parameters:
sql (str) – A SQL query.
results_table (str, optional) – A table name, not including a project_id or dataset_id. The table name is used as a cache key (if the table already exists, we ignore
sql
and return the table’s contents), so it is wise forresults_table
to include a hash ofsql
.replace_tables (bool) – Indicates if the results table should be replaced with new results, if that table is found.