Last active
June 6, 2024 19:48
-
-
Save t0mpere/724236b650ae60fe6e7720514779c577 to your computer and use it in GitHub Desktop.
anonymization dbt macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro anonymize(column_name, function, add_alias=True) %} | |
{% if execute %} | |
{% call statement('salt', fetch_result=True) %} | |
select salt from sources.private.salt limit 1; | |
{% endcall %} | |
{% set salt = load_result('salt')['data'][0][0] %} | |
{% if function == 'full_hash' %} | |
SHA256(concat({{ column_name }},'{{ salt }}')) | |
{% endif %} | |
{% if function == 'hash_email' %} | |
SHA256(concat(split({{ column_name }},'@')[0],'{{ salt }}')) || '@' || split({{ column_name }},'@')[1] | |
{% endif %} | |
{% if add_alias %} | |
as {{ column_name }} | |
{% endif %} | |
{% endif %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment