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

add generate_surrogate_key macro #685

Merged
merged 7 commits into from
Sep 28, 2022

Conversation

dave-connors-3
Copy link
Contributor

resolves #488

This is a:

  • documentation update
  • bug fix with no breaking changes
  • new functionality
  • a breaking change

All pull requests from community contributors should target the main branch (default).

Description & motivation

This PR is a breaking change for users of the surrogate_key macro -- dbt_utils.surrogate_key now throws a compilation error, and the generate_surrogate_key macro uses a default value for the coalesce function of _dbt_utils_surrogate_key_null_ to disambiguate from empty string values.

Parity can be achieved by adding a boolean variable to your dbt project:

# dbt_project.yml
...
vars:
  dbt_utils:
    surrogate_key_treat_nulls_as_empty_strings: True

Checklist

  • This code is associated with an Issue which has been triaged and accepted for development.
  • I have verified that these changes work locally on the following warehouses (Note: it's okay if you do not have access to all warehouses, this helps us understand what has been covered)
    • BigQuery
    • Postgres
    • Redshift
    • Snowflake
  • I followed guidelines to ensure that my changes will work on "non-core" adapters by:
    • dispatching any new macro(s) so non-core adapters can also use them (e.g. the star() source)
    • using the limit_zero() macro in place of the literal string: limit 0
    • using dbt.type_* macros instead of explicit datatypes (e.g. dbt.type_timestamp() instead of TIMESTAMP
  • I have updated the README.md (if applicable)
  • I have added tests & descriptions to my models (and macros if applicable)
  • I have added an entry to CHANGELOG.md

Maayan-s and others added 3 commits September 20, 2022 07:34
* Update from template to dbt copyright

I want to give proper attribution and licensing to code from dbt_utils that I'm using, so made this fix. Hope it's ok.

* Update LICENSE
@dave-connors-3 dave-connors-3 marked this pull request as ready for review September 26, 2022 21:44
@dave-connors-3
Copy link
Contributor Author

@joellabes -- assuming tests pass here I think we're in decent shape -- decided not to take the handling for non-list args into the new world of generate_surrogate_key -- if we're breaking everyone's project, we might as well break it for the better

Copy link
Contributor

@joellabes joellabes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wonderful! Thank you @dave-connors-3. In the interest of getting the next beta out, I'm going to accept my suggestions and merge this, but if you want to make any changes then there will be another beta release before GA I'm sure!

macros/sql/generate_surrogate_key.sql Outdated Show resolved Hide resolved
macros/sql/surrogate_key.sql Outdated Show resolved Hide resolved
@joellabes joellabes changed the base branch from main to utils-v1 September 28, 2022 03:04
Copy link
Contributor

@joellabes joellabes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Treat blank strings differently to nulls in surrogate_key()
3 participants