forked from dbt-labs/dbt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unpivot.sql
More file actions
29 lines (26 loc) · 908 Bytes
/
test_unpivot.sql
File metadata and controls
29 lines (26 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- snowflake messes with these tests pretty badly since the
-- output of the macro considers the casing of the source
-- table columns. Using some hacks here to get this to work,
-- but we should consider lowercasing the unpivot macro output
-- at some point in the future for consistency
{% if target.name == "snowflake" %} {% set exclude = ["CUSTOMER_ID", "CREATED_AT"] %}
{% else %} {% set exclude = ["customer_id", "created_at"] %}
{% endif %}
select
customer_id,
created_at,
case when '{{ target.name }}' = 'snowflake' then lower(prop) else prop end as prop,
val
from
(
{{
dbt_utils.unpivot(
relation=ref("data_unpivot"),
cast_to=dbt_utils.type_string(),
exclude=exclude,
remove=["name"],
field_name="prop",
value_name="val",
)
}}
) as sbq