Skip to content

Instantly share code, notes, and snippets.

@shashisingh
Forked from t0mpere/anonymize.sql
Created December 9, 2021 11:49
Show Gist options
  • Save shashisingh/fe6fdc6bdd487d96dcf6aa2685bf43cb to your computer and use it in GitHub Desktop.
Save shashisingh/fe6fdc6bdd487d96dcf6aa2685bf43cb 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