File tree 2 files changed +24
-1
lines changed 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 66
66
the variable name (ex. ``$my_dict_var``). See ``In[6]`` and ``In[7]``
67
67
in the Examples section below.
68
68
* ``<query>`` (required, cell argument):
69
- SQL query to run.
69
+ SQL query to run. If the query does not contain any whitespace (aside
70
+ from leading and trailing whitespace), it is assumed to represent a
71
+ fully-qualified table ID, and the latter's data will be fetched.
70
72
71
73
Returns:
72
74
A :class:`pandas.DataFrame` with the query results.
@@ -506,6 +508,11 @@ def _cell_magic(line, query):
506
508
507
509
query = query .strip ()
508
510
511
+ if not query :
512
+ error = ValueError ("Query is missing." )
513
+ _handle_error (error , args .destination_var )
514
+ return
515
+
509
516
# Any query that does not contain whitespace (aside from leading and trailing whitespace)
510
517
# is assumed to be a table id
511
518
if not re .search (r"\s" , query ):
Original file line number Diff line number Diff line change @@ -800,6 +800,22 @@ def test_bigquery_magic_w_table_id_invalid():
800
800
assert "Traceback (most recent call last)" not in output
801
801
802
802
803
+ def test_bigquery_magic_w_missing_query ():
804
+ ip = IPython .get_ipython ()
805
+ ip .extension_manager .load_extension ("google.cloud.bigquery" )
806
+ magics .context ._project = None
807
+
808
+ cell_body = " \n \n \t \t \n "
809
+
810
+ with io .capture_output () as captured_io :
811
+ ip .run_cell_magic ("bigquery" , "df" , cell_body )
812
+
813
+ output = captured_io .stderr
814
+ assert "Could not save output to variable" in output
815
+ assert "Query is missing" in output
816
+ assert "Traceback (most recent call last)" not in output
817
+
818
+
803
819
@pytest .mark .usefixtures ("ipython_interactive" )
804
820
@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
805
821
def test_bigquery_magic_w_table_id_and_destination_var ():
You can’t perform that action at this time.
0 commit comments