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

Associating labels with BigQuery queries #1566

Open
tombaeyens opened this issue Sep 2, 2022 · 1 comment
Open

Associating labels with BigQuery queries #1566

tombaeyens opened this issue Sep 2, 2022 · 1 comment

Comments

@tombaeyens
Copy link
Contributor

It seems that through the BigQuery command line, it's possible to add labels to jobs / queries: https://cloud.google.com/bigquery/docs/adding-labels#adding_a_label_to_a_job

What I didn't find yet is how to set those labels through the PEP 249 DBAPI using Google's BigQuery Python library as the driver: https://cloud.google.com/python/docs/reference/bigquery/latest/dbapi

Ideally it would be possible in the creation of the DBAPI connecttion somehow

            self.client = bigquery.Client(
                project=self.project_id,
                credentials=self.credentials,
                default_query_job_config=bigquery.QueryJobConfig(
                    default_dataset=f"{self.project_id}.{self.dataset}",
                ),
                location=self.location,
                client_info=self.client_info,
                client_options=self.client_options,
            )
            self.connection = dbapi.Connection(self.client)

But I didn't find that yet. Or alternatively it could possible to add the labels when executing the queries,

but that would be harder to implement i think.

Any suggestions?

@linderttobias
Copy link
Contributor

linderttobias commented Sep 15, 2022

Hi @tombaeyens,

this is a great idea to add. Labels for queries are actually quite useful !

Could you not just pass the labels attribute to the QueryJobConfig?
See https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.job.QueryJobConfig#google_cloud_bigquery_job_QueryJobConfig_labels

e.g:

 self.client = bigquery.Client(
                project=self.project_id,
                credentials=self.credentials,
                default_query_job_config=bigquery.QueryJobConfig(
                    default_dataset=f"{self.project_id}.{self.dataset}",
                    labels={"environemnt": "testing"}
                ),
                location=self.location,
                client_info=self.client_info,
                client_options=self.client_options,
            )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants