dbt-labs / dbt-labs/dbt

[Feature] Merge strategy for BQ labels

Open
#15,671 3 comments 0 reactions 0 assignees View on GitHub
area:engine engine:v1 engine:v2 status:triage triage type:feature
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

### Is this your first time submitting a feature request?

- [x] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [x] I have searched the existing issues, and I could not find an existing issue for this feature
- [x] 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

https://github.com/dbt-labs/dbt-core/pull/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'
```

2. Create following files:

dbt_project.yml

```yml
name: 'labelstest'
profile: default

models:
labelstest:
+labels:
dbt_project: labelstest
intermediate:
+labels:
layer: intermediate
```

profiles.yml

```yml
default:
target: dev
outputs:
dev:
dataset: dbt
method: oauth
project: gcp-project-dev
type: bigquery
```

models/intermediate/itm_test.sql

```sql
{{ config(
materialized='view',
labels={'schedule': 'daily'},
) }}
```

3. Running `dbt ls --output json --quiet | jq '.config.labels'` will show:

```json
{
"schedule": "daily"
}
```

But the expected value would be:

```json
{
"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 https://github.com/dbt-labs/dbt-core/pull/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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.