dbt-labs / dbt-labs/docs.getdbt.com
Document model contracts for structs (nested columns) on BigQuery
- Dominant language
- JavaScript
- Stars
- 215
- Forks
- 1.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 130
Description
### Contributions
- [x] I have read the contribution docs, and understand what's expected of me.
### Link to the page on docs.getdbt.com requiring updates
https://docs.getdbt.com/docs/mesh/govern/model-contracts
### What part(s) of the page would you like to see updated?
Add an FAQ about model contracts for nested fields. This is specifically supported on BigQuery. Copying the example from https://github.com/dbt-labs/dbt-bigquery/pull/738:
> ```yaml
> -- nested_fields.yml
> version: 2
>
> models:
> - name: double_nested_fields
> config:
> contract: {enforced: true}
> materialized: table
> columns:
> - name: a
> data_type: string
> - name: b.id
> data_type: integer
> constraints:
> - type: not_null
> - name: b.name
> description: test description
> data_type: string
> - name: b.double_nested.id
> data_type: integer
> - name: b.double_nested.another.again
> data_type: string
> - name: b.double_nested.another.even_more
> data_type: integer
> constraints:
> - type: not_null
> ```
> ```sql
> -- double_nested_fields.sql
> select
> 'string' as a,
> struct(
> 1 as id,
> 'name' as name,
> struct(2 as id, struct('test' as again, '2' as even_more) as another) as double_nested
> ) as b
> ```
> ```
> ❯ dbt run --select double_nested_fields --project-dir ~/basic-dbt
> ```
> ```
> ...
> 21:31:07
> 21:31:07 Compilation Error in model double_nested_fields (models/double_nested_fields.sql)
> 21:31:07 This model has an enforced contract that failed.
> 21:31:07 Please ensure the name, data_type, and number of columns in your contract match the columns in your model's > > definition.
> 21:31:07
> 21:31:07 | column_name | definition_type | contract_type | mismatch_reason |
> 21:31:07 | --------------------------------- | --------------- | ------------- | ------------------ |
> 21:31:07 | b.double_nested.another.even_more | STRING | INT64 | data type mismatch |
> ```
> Fixing the incorrect data type, dbt run passes ✅
### Additional information
Context:
- https://github.com/dbt-labs/dbt-bigquery/pull/738
- https://github.com/dbt-labs/dbt-core/issues/7759
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.