-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds 3 parameters to unpivot: remove, field_name, value_name
- Loading branch information
1 parent
b383a44
commit 178900e
Showing
8 changed files
with
103 additions
and
46 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
customer_id,created_at,status,segment | ||
123,2017-01-01,active,tier 1 | ||
234,2017-02-01,active,tier 3 | ||
567,2017-03-01,churned,tier 2 | ||
customer_id,created_at,status,segment,name | ||
123,2017-01-01,active,tier 1,name 1 | ||
234,2017-02-01,active,tier 3,name 3 | ||
567,2017-03-01,churned,tier 2,name 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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
customer_id,created_at,field_name,value | ||
123,2017-01-01,status,active | ||
123,2017-01-01,segment,tier 1 | ||
234,2017-02-01,status,active | ||
234,2017-02-01,segment,tier 3 | ||
567,2017-03-01,status,churned | ||
567,2017-03-01,segment,tier 2 | ||
customer_id,created_at,prop,val | ||
123,"2017-01-01","segment","tier 1" | ||
123,"2017-01-01","status","active" | ||
123,"2017-01-01","name","name 1" | ||
234,"2017-02-01","segment","tier 3" | ||
234,"2017-02-01","status","active" | ||
234,"2017-02-01","name","name 3" | ||
567,"2017-03-01","status","churned" | ||
567,"2017-03-01","name","name 2" | ||
567,"2017-03-01","segment","tier 2" |
10 changes: 10 additions & 0 deletions
10
integration_tests/data/sql/data_unpivot_original_api_expected.csv
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,field_name,value | ||
123,2017-01-01,status,active | ||
123,2017-01-01,segment,tier 1 | ||
234,2017-02-01,status,active | ||
234,2017-02-01,segment,tier 3 | ||
567,2017-03-01,status,churned | ||
567,2017-03-01,segment,tier 2 | ||
123,2017-01-01,name,name 1 | ||
234,2017-02-01,name,name 3 | ||
567,2017-03-01,name,name 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
32 changes: 32 additions & 0 deletions
32
integration_tests/models/sql/test_unpivot_original_api.sql
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 @@ | ||
|
||
-- unpivot() was enhanced with 3 new parameters | ||
-- This test targets the original API. | ||
|
||
-- 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(FIELD_NAME) | ||
else field_name | ||
end as field_name, | ||
value | ||
|
||
from ( | ||
{{ dbt_utils.unpivot( | ||
table=ref('data_unpivot'), | ||
cast_to=dbt_utils.type_string(), | ||
exclude=exclude | ||
) }} | ||
) 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