Skip to content

Commit

Permalink
added max_results magic option and fixed broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shubha-rajan committed Sep 4, 2019
1 parent b04cc37 commit 7176592
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bigquery/google/cloud/bigquery/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ def _run_query(client, query, job_config=None, max_results=None):
default=None,
help=("Project to use for executing this query. Defaults to the context project."),
)

@magic_arguments.argument(
"--max_results",
default=None,
help=(
"Maximum number of rows in dataframe returned from executing the query."
"Defaults to returning all rows."
),
)

@magic_arguments.argument(
"--max_results",
default=None,
Expand Down
12 changes: 12 additions & 0 deletions bigquery/tests/unit/test_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,11 @@ def test_bigquery_magic_with_legacy_sql():
with run_query_patch as run_query_mock:
ip.run_cell_magic("bigquery", "--use_legacy_sql", "SELECT 17 AS num")

<<<<<<< HEAD
job_config_used = run_query_mock.call_args_list[0][1]["job_config"]
=======
job_config_used = run_query_mock.call_args_list[0][1]['job_config']
>>>>>>> d4fa587dacf... added max_results magic option and fixed broken tests
assert job_config_used.use_legacy_sql is True


Expand Down Expand Up @@ -975,9 +979,13 @@ def test_bigquery_magic_with_string_params():
run_query_mock.return_value = query_job_mock

ip.run_cell_magic("bigquery", 'params_string_df --params {"num":17}', sql)
<<<<<<< HEAD
run_query_mock.assert_called_once_with(
mock.ANY, sql.format(num=17), mock.ANY, max_results=None
)
=======
run_query_mock.assert_called_once_with(mock.ANY, sql.format(num=17), mock.ANY, max_results=None)
>>>>>>> d4fa587dacf... added max_results magic option and fixed broken tests

assert "params_string_df" in ip.user_ns # verify that the variable exists
df = ip.user_ns["params_string_df"]
Expand Down Expand Up @@ -1012,9 +1020,13 @@ def test_bigquery_magic_with_dict_params():
# Insert dictionary into user namespace so that it can be expanded
ip.user_ns["params"] = params
ip.run_cell_magic("bigquery", "params_dict_df --params $params", sql)
<<<<<<< HEAD
run_query_mock.assert_called_once_with(
mock.ANY, sql.format(num=17), mock.ANY, max_results=None
)
=======
run_query_mock.assert_called_once_with(mock.ANY, sql.format(num=17), mock.ANY, max_results=None)
>>>>>>> d4fa587dacf... added max_results magic option and fixed broken tests

assert "params_dict_df" in ip.user_ns # verify that the variable exists
df = ip.user_ns["params_dict_df"]
Expand Down

0 comments on commit 7176592

Please sign in to comment.