Search code examples
pandasgoogle-bigquery

pandas_gbq unable to attach label to bigquery job


I've tried to attach labels to bigquery jobs, this should work via Bigquery API like:

df = pd.read_gbq(sql, project_id=project_id, dialect='standard', configuration=query_config)

query_config = {
        "query": {
            "labels": {
                "label": "labelName"
            }
        }
    }

but it won't attach labels at all.

While googles bigquery connector works flawlessly:

df = client.query(sql, job_config=query_config, project=project_id).to_dataframe()

query_config = bigquery.QueryJobConfig(
    labels={
        'label': 'labelName'
    }
)

Am I misreading the documentaion of the BigQuery API? Thank you in advance


Solution

  • Look at the structure of the REST request: https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#queryrequest

    The labels field should not be inside the query field:

    config = {
        "labels": {
           "label": "labelName"
        }
    }
    
    df = pd.read_gbq(sql, project_id=project_id, dialect='standard', configuration=config)