generated from dbt-labs/jaffle-shop-template
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jordan
committed
Aug 1, 2024
1 parent
1829a16
commit 0cf0a85
Showing
22 changed files
with
26 additions
and
156,536 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 |
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,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 |
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,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') }} |
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,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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.