Skip to content

Commit

Permalink
Merge pull request #74 from fishtown-analytics/adapter-hash
Browse files Browse the repository at this point in the history
hash macro + update surrogate_key
  • Loading branch information
jtcohen6 authored Jul 25, 2018
2 parents afd04b0 + d3e6589 commit 7469d67
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions integration_tests/data/cross_db/data_hash.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
input_1,output
ab,187ef4436122d1cc2f40dc2b92f0eba0
a,0cc175b9c0f1b6a831c399e269772661
1,c4ca4238a0b923820dcc509a6f75849b
,d41d8cd98f00b204e9800998ecf8427e
5 changes: 5 additions & 0 deletions integration_tests/models/cross_db_utils/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ test_datediff:
assert_equal:
- { actual: actual, expected: expected }

test_hash:
constraints:
assert_equal:
- { actual: actual, expected: expected }

test_last_day:
constraints:
assert_equal:
Expand Down
12 changes: 12 additions & 0 deletions integration_tests/models/cross_db_utils/test_hash.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

with data as (

select * from {{ ref('data_hash') }}

)

select
{{ dbt_utils.hash('input_1') }} as actual,
output as expected

from data
13 changes: 13 additions & 0 deletions macros/cross_db_utils/hash.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% macro hash(field) -%}
{{ adapter_macro('dbt_utils.hash', field) }}
{%- endmacro %}


{% macro default__hash(field) -%}
md5(cast({{field}} as {{dbt_utils.type_string()}}))
{%- endmacro %}


{% macro bigquery__hash(field) -%}
to_hex({{dbt_utils.default__hash(field)}})
{%- endmacro %}
2 changes: 1 addition & 1 deletion macros/sql/surrogate_key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

{%- endfor -%}

md5({{dbt_utils.concat(fields)}})
{{dbt_utils.hash(dbt_utils.concat(fields))}}

{%- endmacro -%}

0 comments on commit 7469d67

Please sign in to comment.