Environment:
dbt 1.3, dbt could beta, snowflake, windows
packages:
- package: dbt-labs/dbt_utils
version: 0.9.2
Issue:
doing this: {{ dbt_utils.surrogate_key(dbt_utils.get_filtered_columns_in_relation( source('source', 'table'))) }}
Produces this 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. The dbt_.foo_bar model triggered this warning.
The warning makes a lot of sense to me. But I’m having trouble fixing it…
Adding square brackets like this: {{ dbt_utils.surrogate_key(dbt_utils.get_filtered_columns_in_relation([ source('source', 'table'))]) }}
produces SQL which is not what I’d expect.
By that I mean:
instead of md5(cast(coalesce(cast(field1 as TEXT), '') || '-' || coalesce(cast(field2 as TEXT), '') as TEXT))
I’m getting md5(cast(coalesce(cast(['field1', 'field2'])))
More detailed example:
print get_filtered_columns_in_relation to see what it looks like:
{% set column_list = dbt_utils.get_filtered_columns_in_relation( source('source', 'table')) %}
-- print the column list to see what it looks like
{{column_list}}
-- it prints something that looks like a list, surrounded in square brackets. example ['field1','field2']
-- manually add some square brackets as another test
{% set column_list2 = [dbt_utils.get_filtered_columns_in_relation( source('source', 'table'))] %}
-- print the column list 2 to see what it looks like
{{column_list2}}
-- it prints something that looks like a list, with one list in it. example [['field1','field2']]
Try to use it in SQL
with example as
(
select *,
{{ dbt_utils.surrogate_key(column_list) }},
-- the above line produces the new warning
{{ dbt_utils.surrogate_key(column_list2) }}
-- the above produces the strange sql which does not coalesce nulls, etc
from
source('source', 'table')
)
select * from example
I hope this makes sense!