Skip to content
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

Auto-named constraints does not take into account for the model/table name #747

Closed
elca-anh opened this issue Jul 29, 2024 · 3 comments · Fixed by #774
Closed

Auto-named constraints does not take into account for the model/table name #747

elca-anh opened this issue Jul 29, 2024 · 3 comments · Fixed by #774
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@elca-anh
Copy link
Contributor

Describe the feature

Column constraints can be named explicitly or automatically in the YAML model documentation.
When done automatically, the name is created by hashing the name of the column. Since constraint name shall be unique per schema, this is far from ideal as multiple columns might have the same name.
Explicit naming is not magic either since there can be no expansion of the name. In our case, we use prefixes to have several versions of the models in the dev environment. Since there are no macros within the YAML we cannot use the prefix in the constraint name.

Current code in dbt-databricks\dbt\include\databricks\macros\relations\constraints.sql:107:
{% set name = constraint.get("name") %}
{% if not name and local_md5 %}
{{ exceptions.warn("Constraint of type " ~ type ~ " with no name provided. Generating hash instead.") }}
{%- set name = local_md5 (column.get("name", "") ~ ";" ~ expression ~ ";") -%}
{% endif %}

Describe alternatives you've considered

Add the model name as part of the hash

Additional context

Constraint documentation on models within YAML file.

Who will this benefit?

Model documentation

Are you interested in contributing this feature?

Yes, I can contribute on the validation of this feature and other tests

@elca-anh elca-anh added the enhancement New feature or request label Jul 29, 2024
@benc-db
Copy link
Collaborator

benc-db commented Jul 30, 2024

This is a valid request that I do not have capacity to fix at the moment. I would be happy to provide feedback on a PR if you open one. Thanks 👍

@benc-db benc-db added good first issue Good for newcomers help wanted Extra attention is needed labels Jul 30, 2024
@elca-anh
Copy link
Contributor Author

elca-anh commented Aug 5, 2024

Hello, I will do it as soon as I get some time to test it

@elca-anh
Copy link
Contributor Author

To test the constraint naming in test_contraints_macros.py, I need the macro "local_md5" or to mock it (better).
How can I do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants