dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.96k stars 1.63k forks source link

[Feature] Constraint names #10925

Open joshuataylor opened 3 weeks ago

joshuataylor commented 3 weeks ago

Is this your first time submitting a feature request?

Describe the feature

Constraints support names with dbt: https://docs.getdbt.com/reference/resource-properties/constraints

Right now adding a name like this:

- name: foobar
  data_type: integer
  constraints:
    - type: check
      expression: "foobar >= 0"
      name: "custom_foobar_constraint"

Would result in an error like this:

10:59:21  Database Error in model fct_foobar (some_path?fct_foobar.sql)
10:59:21    new row for relation "fct_foobar__dbt_tmp" violates check constraint "fct_foobar__dbt_tmp_check"
10:59:21    DETAIL:  Failing row contains (942).
10:59:21    compiled Code at target/run/fct_foobar.sql

A name is super handy for figuring out which constraint is actually failing.

Describe alternatives you've considered

dbt tests

Who will this benefit?

Users of constraints.

Are you interested in contributing this feature?

Yes, pending decision.

Anything else?

Happy to contribute this, I believe it'll need to be worked out a bit, due to possible syntax changes if a name is provided.

amychen1776 commented 2 weeks ago

This is a very interesting idea! I'm going to transfer to the core repository because I do believe this would need to be applied via the core codebase @dbeatty10