Description
In situations where a user already has a google.cloud.bigquery.Client
object, it'd be helpful to be able to create an sqlalchemy engine either using that already existing BigQuery client object or the same credentials used by that client.
I'm poking around and one option would be something like
bq_client: bigquery.Client
engine = sqlalchemy.engine.create_engine(
'bigquery://project/?credentials_user_info_json=%s' % bq_client._credentials.to_json())
to create a client with the same credentials. This is unfortunately accessing a private _credentials
attribute on the client. We might look to adding a public interface for this on the client so callers don't need to access _credentials
.
I was also looking at something like
bq_client: bigquery.Client
engine = sqlalchemy.engine.create_engine(
'bigquery://project', connect_args={'client': bq_client})
using the connect_args kwarg
The problem is that the engine will still try to create the client itself even if it will end up being replaced by the one from connnect_args
. That attempt to create the client by the engine may fail (we're assuming the big query client is created by some machinery that's opaque to the user here.) I'm not seeing a clean way to avoid this.
Any other suggestions? I'm more than happy to work on this if it seems like a reasonable thing to support!