%%bqsql cell magics#
The BigQuery DataFrames (aka BigFrames) package provides a %%bqsql cell magics for Jupyter environments.
To use it, first activate the extension:
%load_ext bigframes
Now, use the magics by including SQL in the body.
%%bqsql
SELECT * FROM `bigquery-public-data.usa_names.usa_1910_2013`
Query processed 0 Bytes. [Job bigframes-dev:US.job_UVe7FsupxF3CbYuLcLT7fpw9dozg details]
The output DataFrame can be saved to a variable.
%%bqsql mydf
SELECT * FROM `bigquery-public-data.usa_names.usa_1910_2013`
Query processed 0 Bytes. [Job bigframes-dev:US.c142adf3-cd95-42da-bbdc-c176b36b934f details]
You can chain cells together using format strings. DataFrame objects are automatically turned into table expressions.
%%bqsql
SELECT sum(number) as total_count, name
FROM {mydf}
WHERE name LIKE 'Tr%'
GROUP BY name
ORDER BY total_count DESC
Query processed 88.1 MB in a moment of slot time.