Environment details
- OS type and version: jupyter notebook
- Python version: Python 3.7.3
- pip version: pip 20.1.1
- google-cloud-bigquery version: 1.25.0
Steps to reproduce
This is a missing option that do exists in google bigquery client - "https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client"
But is missing from "https://github.com/googleapis/python-bigquery/blob/master/google/cloud/bigquery/magics.py"
Code example
client=bigquery.Client(
project=project,
credentials=context.credentials,
default_query_job_config=context.default_query_job_config,
client_info=client_info.ClientInfo(user_agent=IPYTHON_USER_AGENT),
)
Note the the client_option is missing in creating the client in the code above
The patch to apply to fix this flow:
diff --git a/google/cloud/bigquery/magics.py b/google/cloud/bigquery/magics.py
index 7128e32..00e26d0 100644
--- a/google/cloud/bigquery/magics.py+++ b/google/cloud/bigquery/magics.py@@ -140,6 +140,10 @@
Out[7]: num
...: -------
...: 0 17
+ Executing query with job ID: bf633912-af2c-4780-b568-5d868058632b+ Query executing: 2.61s+ Query complete after 2.92s+
"""
from __future__ import print_function
@@ -183,6 +187,7 @@ class Context(object):
self._project = None
self._connection = None
self._default_query_job_config = bigquery.QueryJobConfig()
+ self._client_options = google.api_core.client_options.ClientOptions()
@property
def credentials(self):
@@ -244,6 +249,30 @@ class Context(object):
def project(self, value):
self._project = value
+ @property+ def client_options(self):+ """ google.api_core.client_options.ClientOptions: client options to be used through IPython+ Magics++ Note::+ The client options does not need to be explicitly defined if you have an+ no special network conenctions are required. Normally you would+ be using https://www.googleapis.com/ end point++ Example:+ Manually setting the endpoint:++ >>> from google.cloud.bigquery import magics+ >>> client_option = {}+ >>> client_option['api_endpoint'] = "https://some.special.url"+ >>> magics.context.client_options = client_option+ """+ return self._client_options++ @client_options.setter+ def client_options(self, value):+ self._client_options = value+
@property
def default_query_job_config(self):
"""google.cloud.bigquery.job.QueryJobConfig: Default job
@@ -459,6 +488,18 @@ def _create_dataset_if_necessary(client, dataset_id):
"name (ex. $my_dict_var)."
),
)
+@magic_arguments.argument(+ "--options",+ nargs="+",+ default=None,+ help=(+ "Parameters to format the query string. If present, the --options "+ "flag should be followed by a string representation of a dictionary "+ "in the format (Union[google.api_core.client_options.ClientOptions, Dict])"+ "or a reference to a dictionary in the same format. The dictionary "+ "key/value matches does at google.api_core.client_options.ClientOptions"+ ),+)
def _cell_magic(line, query):
"""Underlying function for bigquery cell magic
@@ -501,6 +542,7 @@ def _cell_magic(line, query):
credentials=context.credentials,
default_query_job_config=context.default_query_job_config,
client_info=client_info.ClientInfo(user_agent=IPYTHON_USER_AGENT),
+ client_options=context.client_options
)
if context._connection:
client._connection = context._connection
Environment details
Steps to reproduce
This is a missing option that do exists in google bigquery client - "https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client"
But is missing from "https://github.com/googleapis/python-bigquery/blob/master/google/cloud/bigquery/magics.py"
Code example
Note the the client_option is missing in creating the client in the code above
The patch to apply to fix this flow: