File tree Expand file tree Collapse file tree 5 files changed +35
-8
lines changed
Expand file tree Collapse file tree 5 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -101,3 +101,15 @@ Perform a query
101101 GROUP BY name
102102 ORDER BY count DESC
103103 LIMIT 3
104+
105+ Since BigQuery supports Python via BigQuery DataFrames, `%%bqsql ` is offered as
106+ an alias to clarify the language of these cells.
107+
108+ .. code :: python
109+
110+ %% bqsql
111+ SELECT name, SUM(number) as count
112+ FROM ' bigquery-public-data.usa_names.usa_1910_current'
113+ GROUP BY name
114+ ORDER BY count DESC
115+ LIMIT 3
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ def load_ipython_extension(ipython):
2727 ipython .register_magic_function (
2828 _cell_magic , magic_kind = "cell" , magic_name = "bigquery"
2929 )
30+ ipython .register_magic_function (_cell_magic , magic_kind = "cell" , magic_name = "bqsql" )
3031
3132
3233__all__ = (
Original file line number Diff line number Diff line change 1414
1515"""IPython Magics
1616
17- .. function:: %%bigquery
17+ .. function:: `` %%bigquery`` or ``%%bqsql``
1818
1919 IPython cell magic to run a query and display the result as a DataFrame
2020
2121 .. code-block:: python
2222
23- %%bigquery [<destination_var>] [--project <project>] [--use_legacy_sql]
23+ %%bqsql [<destination_var>] [--project <project>] [--use_legacy_sql]
2424 [--verbose] [--params <params>]
2525 <query>
2626
7474 fully-qualified table ID, and the latter's data will be fetched.
7575
7676 Returns:
77- A :class:`pandas.DataFrame` with the query results.
77+ A :class:`pandas.DataFrame` or :class:`bigframes.pandas.DataFrame`
78+ with the query results, depending on the ``engine`` chosen.
7879
7980 .. note::
8081 All queries run using this magic will run using the context
81- :attr:`~google.cloud.bigquery.magics .Context.credentials`.
82+ :attr:`~bigquery_magics.config .Context.credentials`.
8283"""
8384
8485from __future__ import print_function
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ in a Jupyter notebook cell.
88
99 %load_ext bigquery_magics
1010
11- This makes the ``%%bigquery `` magic available.
11+ This makes the ``%%bigquery `` and `` %%bqsql `` magics available.
1212
1313Code Samples
1414------------
@@ -30,5 +30,11 @@ Running a parameterized query:
3030API Reference
3131-------------
3232
33- .. automodule :: google.cloud.bigquery.magics.magics
33+ .. automodule :: bigquery_magics.bigquery
34+ :members:
35+
36+ Configuration
37+ ~~~~~~~~~~~~~
38+
39+ .. automodule :: bigquery_magics.config
3440 :members:
Original file line number Diff line number Diff line change @@ -395,13 +395,20 @@ def test__create_dataset_if_necessary_not_exist():
395395 client .create_dataset .assert_called_once ()
396396
397397
398+ @pytest .mark .parametrize (
399+ ("magic_name" ,),
400+ (
401+ ("bigquery" ,),
402+ ("bqsql" ,),
403+ ),
404+ )
398405@pytest .mark .usefixtures ("ipython_interactive" )
399- def test_extension_load ():
406+ def test_extension_load (magic_name ):
400407 ip = IPython .get_ipython ()
401408 ip .extension_manager .load_extension ("bigquery_magics" )
402409
403410 # verify that the magic is registered and has the correct source
404- magic = ip .magics_manager .magics ["cell" ].get ("bigquery" )
411+ magic = ip .magics_manager .magics ["cell" ].get (magic_name )
405412 assert magic .__module__ == "bigquery_magics.bigquery"
406413
407414
You can’t perform that action at this time.
0 commit comments