Skip to content

[Feature] Merge strategy for BQ labels #15671

Description

@yochem

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Which version of dbt is this feature for?

dbt 1.x, dbt 2.x, tested with dbt-core==1.12.0

Describe the feature

#1964 introduced support for BigQuery labels (a dictionary of key=value pairs). Currently, model config overwrites the labels defined in dbt_project.yml completely. I propose a merge strategy per label key, so we can define labels for whole folders but also model-specific ones.

Minimal working example

  1. Prerequisites
$ mkdir mwe && cd mwe
$ uv venv && uv pip install 'dbt-core==1.12.0' 'dbt-bigquery==1.12.0'
  1. Create following files:
dbt_project.yml
name: 'labelstest'
profile: default

models:
  labelstest:
    +labels:
      dbt_project: labelstest
    intermediate:
      +labels:
        layer: intermediate
profiles.yml
default:
  target: dev
  outputs:
    dev:
      dataset: dbt
      method: oauth
      project: gcp-project-dev
      type: bigquery
models/intermediate/itm_test.sql
{{ config(
  materialized='view',
  labels={'schedule': 'daily'},
) }}
  1. Running dbt ls --output json --quiet | jq '.config.labels' will show:
{
  "schedule": "daily"
}

But the expected value would be:

{
  "schedule": "daily",
  "layer": "intermediate",
  "dbt_project": "labelstest"
}

Describe alternatives you've considered

The alternative is to not define labels in dbt_project.yml and only in the model files, but this gets repeatable and error prone quick.

Who will this benefit?

All users of BigQuery labels.

Are you interested in contributing this feature?

I might, but don't have any knowledge on the codebase so it might take a while
Yes, at least for the Python (v1.*`) version.

Anything else?

First implemented in #1964. I've created the issue on this repo because the PR that introduced the feature was made to this repo, but it might need to be transferred to https://github.com/dbt-labs/dbt-adapters?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:engineCore Fusion engine: CLI, task graph, run-time orchestration.engine:v1Concerns the dbt Core v1 engine (Python).engine:v2Concerns the dbt Fusion (v2) engine.status:triageAwaiting initial triage / categorization.triagetype:featureA new feature or improvement request.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions