Skip to content

Commit 814bf8b

Browse files
committed
Ensure surrogate key handles single arg
1 parent 7cc5d5b commit 814bf8b

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
field_1,field_2,field_3,expected
2-
a,b,c,7b193b3d33184464106f41ddf733783b
3-
a,,c,c5fd1b92380c6222ab0ef67839208624
4-
,,c,267743defab4558f1940311b66274e26
5-
,,,cfab1ba8c67c7c838db98d666f02a132
1+
column_1,column_2,column_3,expected_column_1_only,expected_all_columns
2+
a,b,c,0cc175b9c0f1b6a831c399e269772661,7b193b3d33184464106f41ddf733783b
3+
a,,c,0cc175b9c0f1b6a831c399e269772661,c5fd1b92380c6222ab0ef67839208624
4+
,,c,d41d8cd98f00b204e9800998ecf8427e,267743defab4558f1940311b66274e26
5+
,,,d41d8cd98f00b204e9800998ecf8427e,cfab1ba8c67c7c838db98d666f02a132

integration_tests/models/sql/schema.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ models:
104104
- name: test_surrogate_key
105105
tests:
106106
- assert_equal:
107-
actual: actual_arguments
108-
expected: expected
107+
actual: actual_column_1_only
108+
expected: expected_column_1_only
109109
- assert_equal:
110-
actual: actual_list
111-
expected: expected
110+
actual: actual_all_columns_arguments
111+
expected: expected_all_columns
112+
- assert_equal:
113+
actual: actual_all_columns_list
114+
expected: expected_all_columns
112115

113116
- name: test_union
114117
tests:

integration_tests/models/sql/test_surrogate_key.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ with data as (
66
)
77

88
select
9-
{{ dbt_utils.surrogate_key('field_1', 'field_2', 'field_3') }} as actual_arguments,
10-
{{ dbt_utils.surrogate_key(['field_1', 'field_2', 'field_3']) }} as actual_list,
11-
expected
9+
{{ dbt_utils.surrogate_key('column_1') }} as actual_column_1_only,
10+
expected_column_1_only,
11+
{{ dbt_utils.surrogate_key('column_1', 'column_2', 'column_3') }} as actual_all_columns_arguments,
12+
{{ dbt_utils.surrogate_key(['column_1', 'column_2', 'column_3']) }} as actual_all_columns_list,
13+
expected_all_columns
1214

1315
from data

macros/sql/surrogate_key.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{%- macro surrogate_key(field_list) -%}
22

3-
4-
{%- if varargs|length >= 1 %}
3+
{%- if varargs|length >= 1 or field_list is string %}
54

65
{%- do exceptions.warn("Warning: the `surrogate_key` macro now takes a single list argument instead of multiple string arguments. Support for multiple string arguments will be deprecated in a future release of dbt-utils.") -%}
76

0 commit comments

Comments
 (0)