dbt-checkpoint icon indicating copy to clipboard operation
dbt-checkpoint copied to clipboard

Check that a column name is a certain data type

Open culpgrant opened this issue 1 year ago • 3 comments

Describe the feature you'd like I would love to enforce rules in the warehouse that if a column is called "LOAD_TIMESTAMP" it has to be TIMESTAMP_NTZ data type.

Additional context Just good to apply rules for a large team.

culpgrant avatar Mar 28 '23 15:03 culpgrant

@culpgrant the check-name-contract should do the trick for this! Try this hook:

- id: check-column-name-contract
   args: [--pattern, "LOAD_TIMESTAMP", --dtype, TIMESTAMP_NTZ]

Closing this but feel free to reopen if this doesn't solve your case.

JFrackson avatar Mar 29 '23 11:03 JFrackson

Sorry, I spoke too soon! This hook works both ways for the contract: it will check to make sure that every occurrence of the pattern is enforced as the data type, and that every occurrence of the data type is enforced as the pattern.

Having said that, it could be good to think about an enhancement to that current hook to allow for one-way contracts (e.g. all occurrences of the pattern follow the data type, but not all occurrences of the data type follow the pattern).

I'll reopen this issue and create a new enhancement for that with a bit more detail.

JFrackson avatar Mar 29 '23 11:03 JFrackson

The larger enhancement request has been added here: #121.

JFrackson avatar Mar 29 '23 11:03 JFrackson