Skip to content

Commit

Permalink
Merge pull request #79 from dbt-labs/revert-78-Jstein77-patch-1
Browse files Browse the repository at this point in the history
Revert "setup thin dbt project"
  • Loading branch information
Jstein77 committed Aug 1, 2024
2 parents 1d360bc + fddf785 commit 49160f0
Show file tree
Hide file tree
Showing 22 changed files with 156,536 additions and 26 deletions.
940 changes: 940 additions & 0 deletions jaffle-data/raw_customers.csv

Large diffs are not rendered by default.

95,369 changes: 95,369 additions & 0 deletions jaffle-data/raw_items.csv

Large diffs are not rendered by default.

59,653 changes: 59,653 additions & 0 deletions jaffle-data/raw_orders.csv

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions jaffle-data/raw_products.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sku,name,type,price,description
JAF-001,nutellaphone who dis?,jaffle,1100,nutella and banana jaffle
JAF-002,doctor stew,jaffle,1100,house-made beef stew jaffle
JAF-003,the krautback,jaffle,1200,lamb and pork bratwurst with house-pickled cabbage sauerkraut and mustard
JAF-004,flame impala,jaffle,1400,"pulled pork and pineapple al pastor marinated in ghost pepper sauce, kevin parker's favorite! "
JAF-005,mel-bun,jaffle,1200,"melon and minced beef bao, in a jaffle, savory and sweet"
BEV-001,tangaroo,beverage,600,mango and tangerine smoothie
BEV-002,chai and mighty,beverage,500,oatmilk chai latte with protein boost
BEV-003,vanilla ice,beverage,600,iced coffee with house-made french vanilla syrup
BEV-004,for richer or pourover ,beverage,700,daily selection of single estate beans for a delicious hot pourover
BEV-005,adele-ade,beverage,400,"a kiwi and lime agua fresca, hello from the other side of thirst"
6 changes: 6 additions & 0 deletions jaffle-data/raw_stores.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,name,opened_at,tax_rate
7f790ed7-0fc4-4de2-a1b0-cce72e657fc4,Philadelphia,2016-09-01T00:00:00,0.06
08d44615-06d3-4086-a5d7-21395a1d975e,Brooklyn,2017-03-12T00:00:00,0.04
f6f2bd97-becb-4e1c-a611-20c7cf579841,Chicago,2018-04-29T00:00:00,0.0625
48b0172c-4490-4f05-b290-e69f418d0575,San Francisco,2018-05-09T00:00:00,0.075
ed2af26d-35a1-4a31-ac65-7aedcaa7b7a7,New Orleans,2019-03-10T00:00:00,0.04
66 changes: 66 additions & 0 deletions jaffle-data/raw_supplies.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
id,name,cost,perishable,sku
SUP-001,compostable cutlery - knife,7,False,JAF-001
SUP-002,cutlery - fork,7,False,JAF-001
SUP-003,serving boat,11,False,JAF-001
SUP-004,napkin,4,False,JAF-001
SUP-009,bread,33,True,JAF-001
SUP-011,nutella,46,True,JAF-001
SUP-012,banana,13,True,JAF-001
SUP-001,compostable cutlery - knife,7,False,JAF-002
SUP-002,cutlery - fork,7,False,JAF-002
SUP-003,serving boat,11,False,JAF-002
SUP-004,napkin,4,False,JAF-002
SUP-009,bread,33,True,JAF-002
SUP-010,cheese,20,True,JAF-002
SUP-013,beef stew,169,True,JAF-002
SUP-001,compostable cutlery - knife,7,False,JAF-003
SUP-002,cutlery - fork,7,False,JAF-003
SUP-003,serving boat,11,False,JAF-003
SUP-004,napkin,4,False,JAF-003
SUP-009,bread,33,True,JAF-003
SUP-010,cheese,20,True,JAF-003
SUP-014,lamb and pork bratwurst,234,True,JAF-003
SUP-015,house-pickled cabbage sauerkraut,43,True,JAF-003
SUP-016,mustard,7,True,JAF-003
SUP-001,compostable cutlery - knife,7,False,JAF-004
SUP-002,cutlery - fork,7,False,JAF-004
SUP-003,serving boat,11,False,JAF-004
SUP-004,napkin,4,False,JAF-004
SUP-009,bread,33,True,JAF-004
SUP-010,cheese,20,True,JAF-004
SUP-017,pulled pork,215,True,JAF-004
SUP-018,pineapple,26,True,JAF-004
SUP-021,ghost pepper sauce,20,True,JAF-004
SUP-001,compostable cutlery - knife,7,False,JAF-005
SUP-002,cutlery - fork,7,False,JAF-005
SUP-003,serving boat,11,False,JAF-005
SUP-004,napkin,4,False,JAF-005
SUP-009,bread,33,True,JAF-005
SUP-010,cheese,20,True,JAF-005
SUP-019,melon,33,True,JAF-005
SUP-020,minced beef,124,True,JAF-005
SUP-005,16oz compostable clear cup,13,False,BEV-001
SUP-006,16oz compostable clear lid,4,False,BEV-001
SUP-007,biodegradable straw,13,False,BEV-001
SUP-022,mango,32,True,BEV-001
SUP-023,tangerine,20,True,BEV-001
SUP-005,16oz compostable clear cup,13,False,BEV-002
SUP-006,16oz compostable clear lid,4,False,BEV-002
SUP-007,biodegradable straw,13,False,BEV-002
SUP-008,chai mix,98,True,BEV-002
SUP-024,oatmilk,11,True,BEV-002
SUP-025,whey protein,36,True,BEV-002
SUP-005,16oz compostable clear cup,13,False,BEV-003
SUP-006,16oz compostable clear lid,4,False,BEV-003
SUP-007,biodegradable straw,13,False,BEV-003
SUP-026,coffee,52,True,BEV-003
SUP-027,french vanilla syrup,72,True,BEV-003
SUP-005,16oz compostable clear cup,13,False,BEV-004
SUP-006,16oz compostable clear lid,4,False,BEV-004
SUP-007,biodegradable straw,13,False,BEV-004
SUP-026,coffee,52,True,BEV-004
SUP-005,16oz compostable clear cup,13,False,BEV-005
SUP-006,16oz compostable clear lid,4,False,BEV-005
SUP-007,biodegradable straw,13,False,BEV-005
SUP-028,kiwi,20,True,BEV-005
SUP-029,lime,13,True,BEV-005
66 changes: 60 additions & 6 deletions models/marts/customer360/customers.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
{{
config(
materialized = "view",
)
}}
with

select * from {{ source('semantic_layer_imports', 'customers') }}
customers as (

select * from {{ ref('stg_customers') }}

),

orders_table as (

select * from {{ ref('orders') }}

),

order_items_table as (

select * from {{ ref('order_items') }}
),

order_summary as (

select
customer_id,

count(distinct orders.order_id) as count_lifetime_orders,
count(distinct orders.order_id) > 1 as is_repeat_buyer,
min(orders.ordered_at) as first_ordered_at,
max(orders.ordered_at) as last_ordered_at,
sum(order_items.product_price) as lifetime_spend_pretax,
sum(orders.order_total) as lifetime_spend

from orders_table as orders

left join order_items_table as order_items on orders.order_id = order_items.order_id

group by 1

),

joined as (

select
customers.*,
order_summary.count_lifetime_orders,
order_summary.first_ordered_at,
order_summary.last_ordered_at,
order_summary.lifetime_spend_pretax,
order_summary.lifetime_spend,

case
when order_summary.is_repeat_buyer then 'returning'
else 'new'
end as customer_type

from customers

left join order_summary
on customers.customer_id = order_summary.customer_id

)

select * from joined
62 changes: 56 additions & 6 deletions models/marts/customer360/order_items.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,58 @@
{{
config(
materialized = "view",
)
}}
with

select * from {{ source('semantic_layer_imports', 'order_items') }}
order_items as (

select * from {{ ref('stg_order_items') }}

),


orders as (

select * from {{ ref('stg_orders')}}
),

products as (

select * from {{ ref('stg_products') }}

),

supplies as (

select * from {{ ref('stg_supplies') }}

),

order_supplies_summary as (

select
product_id,
sum(supply_cost) as supply_cost

from supplies

group by 1
),

joined as (
select
order_items.*,
products.product_price,
order_supplies_summary.supply_cost,
products.is_food_item,
products.is_drink_item,
orders.ordered_at

from order_items

left join orders on order_items.order_id = orders.order_id

left join products on order_items.product_id = products.product_id

left join order_supplies_summary on order_items.product_id = order_supplies_summary.product_id

)

select * from joined
--test
51 changes: 45 additions & 6 deletions models/marts/customer360/orders.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
{{
config(
materialized = "view",
)
}}
with
--test
orders as (
select * from {{ ref('stg_orders')}}

select * from {{ source('semantic_layer_imports', 'orders') }}
),

order_items_table as (

select * from {{ ref('order_items')}}

),

order_items_summary as (

select

order_items.order_id,

sum(supply_cost) as order_cost,
sum(is_food_item) as count_food_items,
sum(is_drink_item) as count_drink_items


from order_items_table as order_items

group by 1

),


compute_booleans as (
select

orders.*,
count_food_items > 0 as is_food_order,
count_drink_items > 0 as is_drink_order,
order_cost

from orders

left join order_items_summary on orders.order_id = order_items_summary.order_id
)

select * from compute_booleans
50 changes: 42 additions & 8 deletions models/staging/__sources.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
version: 2

sources:
- name: semantic_layer_imports
- name: ecom
schema: dbt_sl_test
description: Import models for SL
description: E-commerce data
tables:
- name: customers
description: Import customers model
- name: order_items
description: Import order items model
- name: orders
description: Import orders models
- name: raw_customers
description: One record per person who has purchased one or more items
- name: raw_orders
description: One record per order (consisting of one or more order items)
freshness:
warn_after:
count: 24
period: hour
# error_after:
# count: 48
# period: hour
loaded_at_field: ordered_at
- name: raw_items
description: Items included in an order
- name: raw_stores
freshness:
warn_after:
count: 24
period: hour
# error_after:
# count: 48
# period: hour
loaded_at_field: opened_at
- name: raw_products
description: One record per SKU for items sold in stores
- name: raw_supplies
description: One record per supply per SKU of items sold in stores
- name: conversion_sources
schema: '{{ target.schema }}'
description: Source data for conversion metrics
tables:
- name: olist_closed_deals_dataset
- name: home_page_table
- name: olist_customers_dataset
- name: olist_geolocation_dataset
- name: olist_marketing_qualified_leads_dataset
- name: ollist_order_items_dataset
- name: ollist_order_payments_dataset
- name: olist_orders_dataset
- name: olist_sellers_dataset
23 changes: 23 additions & 0 deletions models/staging/stg_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
with

source as (

select * from {{ source('ecom', 'raw_customers') }}

),

renamed as (

select

---------- ids
id as customer_id,

---------- text
name as customer_name

from source

)

select * from renamed
9 changes: 9 additions & 0 deletions models/staging/stg_customers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
models:
- name: stg_customers
description: Customer data with basic cleaning and transformation applied, one row per customer.
columns:
- name: customer_id
description: The unique key for each customer.
tests:
- not_null
- unique
31 changes: 31 additions & 0 deletions models/staging/stg_locations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
with

source as (

select * from {{ source('ecom', 'raw_stores') }}

-- if you generate a larger dataset, you can limit the timespan to the current time with the following line
-- where ordered_at <= {{ var('truncate_timespan_to') }}
),

renamed as (

select

---------- ids
id as location_id,

---------- text
name as location_name,

---------- numerics
tax_rate,

---------- timestamps
{{dbt.date_trunc('day', 'opened_at')}} as opened_at

from source

)

select * from renamed
Loading

0 comments on commit 49160f0

Please sign in to comment.