-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Refinement discussion: #6750
Currently, constraints that are set but unenforceable or unsupported raise warnings in adapter-specific jinja macros. For example: snowflake__get_columns_spec_ddl in dbt-snowflake.
To generalize this warning mechanism, we'll need a new adapter method that can tell dbt whether a constraint is:
- supported & enforced
- supported but not enforced
- not supported
Here's what that might look like for dbt-snowflake, in pseudo code:
@staticmethod
def constraint_support:
return {
"not_null": ConstraintSupport.ENFORCED,
"primary_key": ConstraintSupport.NOT_ENFORCED,
"foreign_key": ConstraintSupport.NOT_ENFORCED,
"unique": ConstraintSupport.NOT_ENFORCED,
"check": ConstraintSupport.NOT_SUPPORTED,
}This mapping could be a static method, or a property, or maybe just a constant class attribute. As long as subclasses of BaseAdapters are able to overwrite it. This mapping should also not be available in the jinja context as it's intended for use within the python adapter implementation and not by end users in user space (jinja).
This method would be called in order to determine whether to raise warnings for unenforced/unsupported constraints (unless the user has disabled via warn_unsupported or warn_unenforced (#7066)). Ideally, warnings would be raised at runtime - during materialization, for legible user-facing logs. The actual method that raises warnings could also be implemented in python, on the adapter, calling warn_or_error and firing an event under the hood. It should be used to replace the existing adapter-specific warning mechanisms.
The constraint_support method should be implemented for each adapter, but the warning implementation should be generalized and only implemented in dbt-core.
Is blocked by:
Blocks: