Skip to content

Instantly share code, notes, and snippets.

@t0mpere
Last active June 6, 2024 19:48
Show Gist options
  • Save t0mpere/724236b650ae60fe6e7720514779c577 to your computer and use it in GitHub Desktop.
Save t0mpere/724236b650ae60fe6e7720514779c577 to your computer and use it in GitHub Desktop.
anonymization dbt macro
{% 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