Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery Client should allow a Connection object to be passed in #7122

Closed
vimota opened this issue Jan 12, 2019 · 5 comments
Closed

BigQuery Client should allow a Connection object to be passed in #7122

vimota opened this issue Jan 12, 2019 · 5 comments
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@vimota
Copy link
Contributor

vimota commented Jan 12, 2019

We (at Kaggle) support a BigQuery Proxy which allows users of our managed Notebooks (Kernels) to query BigQuery without any setup and for free. We do this by allowing them to query public datasets using our own credentials, injected in by a proxy we run that receives requests from the client and forwards it to BigQuery. To support this in the BigQuery client the users use, we have to monkeypatch the client and update the internal instance variable _connection to our own subclass of it (https://github.com/Kaggle/docker-python/blob/2653b37c15556996c964fc6cd33197030c4a4228/patches/kaggle_gcp.py#L48).

It would be less hacky if we could pass the Connection object in the client constructor like we do the Credentials object, or be able to set it as a class variable when we subclass Client.

@tseaver tseaver added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. api: bigquery Issues related to the BigQuery API. labels Jan 14, 2019
@tseaver
Copy link
Contributor

tseaver commented Jan 14, 2019

@tswast Can you comment?

@tswast
Copy link
Contributor

tswast commented Jan 14, 2019

@vimota Is the main purpose of the connection object to pass in extra HTTP headers for your proxy? Is this the sort of thing necessary for other kinds of proxies?

CC @alixhami

@vimota
Copy link
Contributor Author

vimota commented Jan 14, 2019

@tswast
Copy link
Contributor

tswast commented Jan 16, 2019

In general we suggest customers set the HTTPS_PROXY environment variable per http://docs.python-requests.org/en/master/user/advanced/#proxies , but I see that may not be sufficient in your case due to the extra header and the fact this isn't a traditional HTTP proxy.

I'd like for there to be some way to reconcile this with how the gRPC-based clients work rather than make _connection a parameter to the constructor. For example, the transport argument may be a good candidate.

transport (Union[~.DataTransferServiceGrpcTransport,
Callable[[~.Credentials, type], ~.DataTransferServiceGrpcTransport]): A transport
instance, responsible for actually making the API calls.
The default transport uses the gRPC protocol.
This argument may also be a callable which returns a
transport instance. Callables will be sent the credentials
as the first argument and the default transport class as
the second argument.

Transport even takes a credentials object and an address, similar to what you'd like.

credentials (google.auth.credentials.Credentials): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If none
are specified, the client will attempt to ascertain the
credentials from the environment.
address (str): The address where the service is hosted.

Since the Connection object for our hand-written HTTP-based clients is similar to the XTransport object in our gRPC-based clients, maybe we add a "transport" argument that accepts a Connection. Unfortunately they are different in one material way: in gRPC clients it is an error to supply both a transport and credentials object (since transport contains the credentials object). @crwilcox @tseaver WDYT?

@vimota
Copy link
Contributor Author

vimota commented May 17, 2019

I filed a related issue but regarding Magics: #8024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants