dbt-labs / dbt-spark

dbt-spark contains all of the code enabling dbt to work with Apache Spark and Databricks
https://getdbt.com
Apache License 2.0
405 stars 227 forks source link

[CT-2223] [Spark] Add model-level constraints to get_columns_spec_ddl #657

Closed MichelleArk closed 1 year ago

MichelleArk commented 1 year ago

Core issue: https://github.com/dbt-labs/dbt-core/issues/6754

from https://github.com/dbt-labs/dbt-core/issues/7067:

constraint type support
not_null not enforced
primary_key not enforced
foreign_key not enforced
unique not enforced
check not enforced

Spark only supports check constraints at the table-level. Add check constraints set at the model-level after check constraints from columns are added: https://github.com/dbt-labs/dbt-spark/blob/main/dbt/include/spark/macros/adapters.sql#L200

Testing coverage is tricky here because the alter statements run after the create table statement: https://github.com/dbt-labs/dbt-spark/blob/main/tests/functional/adapter/test_constraints.py#L8

Constraint docs: https://docs.delta.io/latest/delta-constraints.html