-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from fishtown-analytics/bool_unpivot
Bool unpivot
- Loading branch information
Showing
9 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
id,my_bool | ||
1,true | ||
2,false | ||
3, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
customer_id,created_at,status,segment,is_updated | ||
123,2017-01-01,active,tier 1,TRUE | ||
234,2017-02-01,active,tier 3,FALSE | ||
567,2017-03-01,churned,tier 2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
customer_id,created_at,prop,val | ||
123,2017-01-01,segment,tier 1 | ||
123,2017-01-01,status,active | ||
123,2017-01-01,is_updated,true | ||
234,2017-02-01,segment,tier 3 | ||
234,2017-02-01,status,active | ||
234,2017-02-01,is_updated,false | ||
567,2017-03-01,status,churned | ||
567,2017-03-01,is_updated, | ||
567,2017-03-01,segment,tier 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
-- 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_bool'), | ||
cast_to=dbt_utils.type_string(), | ||
exclude=exclude, | ||
field_name='prop', | ||
value_name='val' | ||
) }} | ||
) as sbq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% macro cast_bool_to_text(field) %} | ||
{{ adapter.dispatch('cast_bool_to_text', packages = dbt_utils._get_utils_namespaces()) (field) }} | ||
{% endmacro %} | ||
|
||
|
||
{% macro default__cast_bool_to_text(field) %} | ||
cast({{ field }} as text) | ||
{% endmacro %} | ||
|
||
{% macro redshift__cast_bool_to_text(field) %} | ||
case | ||
when {{ field }} is true then 'true' | ||
when {{ field }} is false then 'false' | ||
end::text | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters