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

[Feature] Deterministic Field Order for Generate Surrogate Key Macro

Open sha2fiddy opened this issue 2 years ago • 2 comments

Is this your first time submitting a feature request?

  • [X] I have read the expectations for open source contributors
  • [X] I have searched the existing issues, and I could not find an existing issue for this feature
  • [X] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

When using the dbt_utils.generate_surrogate_key macro, the same set of fields passed in a different order will generate different keys. It would be nice if the field names were sorted in some deterministic way (IE alphabetically) before they were hashed, so that the order in which they are passed to the macro has no effect.

Perhaps this could be a configurable option, if there are reasons why this behavior would not be preferred in some situations.

Describe alternatives you've considered

Using a custom macro to sort the list of fields, then passed the sorted list to generate_surrogate_key.

Who will this benefit?

This would be useful for any case where a Surrogate Key is being generated in multiple models, where the expectation is that the same set of fields will produce the same key, regardless of the order they are passed to the generate_surrogate_key macro.

A common example of this is generating the same key in a FACT and DIM table, where consumers will be joining on this key.

Are you interested in contributing this feature?

No response

Anything else?

No response

sha2fiddy avatar Feb 16 '24 13:02 sha2fiddy

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

github-actions[bot] avatar Aug 15 '24 01:08 github-actions[bot]

bump

sha2fiddy avatar Aug 15 '24 12:08 sha2fiddy