Skip to content

Commit 7469d67

Browse files
authored
Merge pull request #74 from fishtown-analytics/adapter-hash
hash macro + update surrogate_key
2 parents afd04b0 + d3e6589 commit 7469d67

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
input_1,output
2+
ab,187ef4436122d1cc2f40dc2b92f0eba0
3+
a,0cc175b9c0f1b6a831c399e269772661
4+
1,c4ca4238a0b923820dcc509a6f75849b
5+
,d41d8cd98f00b204e9800998ecf8427e

integration_tests/models/cross_db_utils/schema.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ test_datediff:
2424
assert_equal:
2525
- { actual: actual, expected: expected }
2626

27+
test_hash:
28+
constraints:
29+
assert_equal:
30+
- { actual: actual, expected: expected }
31+
2732
test_last_day:
2833
constraints:
2934
assert_equal:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
with data as (
3+
4+
select * from {{ ref('data_hash') }}
5+
6+
)
7+
8+
select
9+
{{ dbt_utils.hash('input_1') }} as actual,
10+
output as expected
11+
12+
from data

macros/cross_db_utils/hash.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% macro hash(field) -%}
2+
{{ adapter_macro('dbt_utils.hash', field) }}
3+
{%- endmacro %}
4+
5+
6+
{% macro default__hash(field) -%}
7+
md5(cast({{field}} as {{dbt_utils.type_string()}}))
8+
{%- endmacro %}
9+
10+
11+
{% macro bigquery__hash(field) -%}
12+
to_hex({{dbt_utils.default__hash(field)}})
13+
{%- endmacro %}

macros/sql/surrogate_key.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
{%- endfor -%}
1616

17-
md5({{dbt_utils.concat(fields)}})
17+
{{dbt_utils.hash(dbt_utils.concat(fields))}}
1818

1919
{%- endmacro -%}

0 commit comments

Comments
 (0)