File tree 2 files changed +29
-0
lines changed
google/cloud/bigquery/magics 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -508,6 +508,15 @@ def _create_dataset_if_necessary(client, dataset_id):
508
508
"Defaults to use tqdm_notebook. Install the ``tqdm`` package to use this feature."
509
509
),
510
510
)
511
+ @magic_arguments .argument (
512
+ "--location" ,
513
+ type = str ,
514
+ default = None ,
515
+ help = (
516
+ "Set the location to execute query."
517
+ "Defaults to location set in query setting in console."
518
+ ),
519
+ )
511
520
def _cell_magic (line , query ):
512
521
"""Underlying function for bigquery cell magic
513
522
@@ -551,6 +560,7 @@ def _cell_magic(line, query):
551
560
category = DeprecationWarning ,
552
561
)
553
562
use_bqstorage_api = not args .use_rest_api
563
+ location = args .location
554
564
555
565
params = []
556
566
if params_option_value :
@@ -579,6 +589,7 @@ def _cell_magic(line, query):
579
589
default_query_job_config = context .default_query_job_config ,
580
590
client_info = client_info .ClientInfo (user_agent = IPYTHON_USER_AGENT ),
581
591
client_options = bigquery_client_options ,
592
+ location = location ,
582
593
)
583
594
if context ._connection :
584
595
client ._connection = context ._connection
Original file line number Diff line number Diff line change @@ -2053,3 +2053,21 @@ def test_bigquery_magic_create_dataset_fails():
2053
2053
)
2054
2054
2055
2055
assert close_transports .called
2056
+
2057
+
2058
+ @pytest .mark .usefixtures ("ipython_interactive" )
2059
+ def test_bigquery_magic_with_location ():
2060
+ ip = IPython .get_ipython ()
2061
+ ip .extension_manager .load_extension ("google.cloud.bigquery" )
2062
+ magics .context .credentials = mock .create_autospec (
2063
+ google .auth .credentials .Credentials , instance = True
2064
+ )
2065
+
2066
+ run_query_patch = mock .patch (
2067
+ "google.cloud.bigquery.magics.magics._run_query" , autospec = True
2068
+ )
2069
+ with run_query_patch as run_query_mock :
2070
+ ip .run_cell_magic ("bigquery" , "--location=us-east1" , "SELECT 17 AS num" )
2071
+
2072
+ client_options_used = run_query_mock .call_args_list [0 ][0 ][0 ]
2073
+ assert client_options_used .location == "us-east1"
You can’t perform that action at this time.
0 commit comments