-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[CT-1358] [Feature] Add column type constraints as dbt native configs #6079
Comments
What this could look and feel like in snowflake: https://www.loom.com/share/14020499f5f646b6bc80c909716850fd |
What if we add version: 2
models:
- name: constraints_example
config:
constraints_enabled: true
columns:
- name: color
data_type: varchar
constraint: value in ('red', 'green', 'yellow', 'blue')
- name: shape
data_type: enum('square', 'circle', 'triangle') |
Good spike! Just in time too, more and more data warehouse providers are adding constraints into their table definitions. For example, databricks have just added table constraints in October 2022: https://docs.databricks.com/tables/constraints.html |
A couple notes on design and scoping dbt-core design:
--example sql file config
{{
config(
materialized = "table",
constraints_enabled = true
)
}}
select
1 as id,
'blue' as color,
cast('2019-01-01' as date) as date_day # schema.yml
version: 2
models:
- name: constraints_example
config:
constraints_enabled: true
columns:
- name: id
data_type: integer
description: I want to describe this one, but I don't want to list all the columns
constraint: not null
- name: color
data_type: string
- name: date_day
data_type: date
default_value: CURRENT_DATE() # dbt_project.yml
models:
+constraints_enabled: true # enforce all models have constraints typed
dbt_artifacts:
+docs:
show: false
+schema: dbt_artifacts_sung
staging:
+schema: dbt_artifacts_sung
tpch:
staging:
database: '{{ env_var("DBT_DYNAMIC_DATABASE","analytics") }}'
+materialized: view
+docs:
node_color: "#FB6962"
marts:
intermediate:
+constraints_enabled: false # overrides the root level enforcement
+docs:
node_color: "#3AAAE0"
core:
+tags: "owner:sung"
materialized: table
+docs:
node_color: "#F6AE3E" adapter design:
|
I volunteer to help contribute the Snowflake portions and help test on a real world project. This will really help with incremental updates especially! |
Team ExpectationsAlign on vision and scope of work: see above
Align on project workflow and how we keep each other accountable:
Feel ready to start working this week:
|
Is this your first time submitting a feature request?
Describe the feature
Problem:
Solution:
Describe alternatives you've considered
Custom Materialization Macro in BigQuery: https://www.loom.com/share/1f1f190e66254d12984962c613e8082d
This is a general design pattern, but uses meta configs to enable this functionality. This is brittle because it injects custom configs into the manifest that aren't guaranteed to behave in expected ways.
Who will this benefit?
dbt users with large projects that need extra robustness in their developer experience and downstream users get the data they expect: data types and all.
Are you interested in contributing this feature?
yes, and I'll be working with someone in the community @jonathanneo
Anything else?
Research:
not null
constraints, the rest are nice to have metadata: https://docs.snowflake.com/en/sql-reference/constraints-overview.html#supported-constraint-typesConsiderations:
check
constraint as pgsql enables it?The text was updated successfully, but these errors were encountered: