Skip to content

Commit

Permalink
setup thin dbt project
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan committed Aug 1, 2024
1 parent 1829a16 commit 0cf0a85
Show file tree
Hide file tree
Showing 22 changed files with 26 additions and 156,536 deletions.
940 changes: 0 additions & 940 deletions jaffle-data/raw_customers.csv

This file was deleted.

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

This file was deleted.

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

This file was deleted.

11 changes: 0 additions & 11 deletions jaffle-data/raw_products.csv

This file was deleted.

6 changes: 0 additions & 6 deletions jaffle-data/raw_stores.csv

This file was deleted.

66 changes: 0 additions & 66 deletions jaffle-data/raw_supplies.csv

This file was deleted.

66 changes: 6 additions & 60 deletions models/marts/customer360/customers.sql
Original file line number Diff line number Diff line change
@@ -1,62 +1,8 @@
with
{{
config(
materialized = "view",
)
}}

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

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: 6 additions & 56 deletions models/marts/customer360/order_items.sql
Original file line number Diff line number Diff line change
@@ -1,58 +1,8 @@
with
{{
config(
materialized = "view",
)
}}

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

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

),

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
select * from {{ source('semantic_layer_imports', 'orders') }}
50 changes: 8 additions & 42 deletions models/staging/__sources.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,13 @@
version: 2

sources:
- name: ecom
- name: semantic_layer_imports
schema: dbt_sl_test
description: E-commerce data
description: Import models for SL
tables:
- 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
- name: customers
description: Import customers model
- name: order_items
description: Import order items model
- name: orders
description: Import orders models
23 changes: 0 additions & 23 deletions models/staging/stg_customers.sql

This file was deleted.

9 changes: 0 additions & 9 deletions models/staging/stg_customers.yml

This file was deleted.

31 changes: 0 additions & 31 deletions models/staging/stg_locations.sql

This file was deleted.

Loading

0 comments on commit 0cf0a85

Please sign in to comment.