Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source macro work #2

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ profile: 'default'
# These configurations specify where dbt should look for different types of files.
# The `source-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
source-paths: ["models"]
model-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
seed-paths: ["data"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

Expand Down
3 changes: 0 additions & 3 deletions models/demo_examples/demo_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ models:
tests:
- unique
- not_null

- name: get_area_of_circle
description: demo to show udfs

118 changes: 0 additions & 118 deletions models/demo_examples/external_sources.yml

This file was deleted.

2 changes: 0 additions & 2 deletions models/demo_examples/get_area_of_circle.sql

This file was deleted.

22 changes: 0 additions & 22 deletions models/marts/aggregates/agg_ship_modes_dynamic_pivot.sql

This file was deleted.

26 changes: 0 additions & 26 deletions models/marts/aggregates/agg_ship_modes_hardcoded_pivot.sql

This file was deleted.

32 changes: 32 additions & 0 deletions models/marts/aggregates/agg_yearly_parts_hardcoded_pivot.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Create a pivot table with hard-coded columns based on a query of the parts that are in the system */

with fct_order_items as (
select * from {{ ref('fct_order_items') }}
),

dim_parts as (
select * from {{ ref('dim_parts') }}
),

merged as (
select
date_part('year', fct_order_items.order_date) as order_year,
dim_parts.name,
fct_order_items.gross_item_sales_amount
from
fct_order_items
inner join dim_parts
on fct_order_items.part_key = dim_parts.part_key
)

select
*
from
merged
-- have to manually map strings in the pivot operation
pivot(sum(gross_item_sales_amount) for name in (
'goldenrod lavender spring chocolate lace' as goldenrod_lavender_spring_chocolate_lace,
'blush thistle blue yellow saddle' as blush_thistle_blue_yellow_saddle
))

order by order_year
13 changes: 3 additions & 10 deletions models/marts/aggregates/aggregates.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@

version: 2

models:
# These two models are just different ways of doing the same thing (pivot over categories) using jinja and the PIVOT operation in Snowflake
- name: agg_ship_modes_hardcoded_pivot
description: Example of creating a pivot table with dynamic columns based on the ship modes that are in the system
columns:
- name: order_year
description: year of the order

- name: agg_ship_modes_dynamic_pivot
description: Example of creating a pivot table with hard-coded columns based on a query of the ship modes that are in the system
- name: agg_yearly_parts_hardcoded_pivot
columns:
- name: order_year
description: year of the order
- name: order_year
2 changes: 1 addition & 1 deletion models/marts/aggregates/exposures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ exposures:

# IMPORTANT: determines the lineage relationship of the exposure construct to the rest of your DAG
depends_on:
- ref('agg_ship_modes_dynamic_pivot')
- ref('agg_yearly_parts_hardcoded_pivot')
Loading