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 %} |
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_columns(database, schema, table) %} | |
{% call statement('mapping', fetch_result=True) %} | |
select m.table_name_filter, s.column_name, function | |
from {{ ref('anonymization_mapping') }} as m | |
right join {{ database }}.information_schema.columns as s | |
on UPPER(m.column_name) = s.column_name | |
where table_name = '{{ table.upper() }}' | |
and table_schema = '{{ schema.upper() }}' | |
order by s.column_name; |
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
{{ config(database='sources') }} | |
{{ config(schema='production') }} | |
-- the following comment is needed by dbt to compile the references in the macro | |
-- depends_on: {{ ref('anonymization_mapping') }} | |
select {{ anonymize_columns('private_sources', 'production', 'users') }} | |
from private_sources.production.users |