Skip to content
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
5 changes: 5 additions & 0 deletions examples/basic/lineage.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flowchart LR
orders_per_product(orders_per_product)
source_orders --> orders_per_product
source_orders(source_orders)
https://storage.googleapis.com/blef-demo/cart.parquet --> source_orders
37 changes: 37 additions & 0 deletions examples/jaffle_shop/marts/customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
with customers as (
select *
from stg_customers
),
orders as (
select *
from stg_orders
),
customer_orders_summary as (
select orders.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(orders.subtotal) as lifetime_spend_pretax,
sum(orders.tax_paid) as lifetime_tax_paid,
sum(orders.order_total) as lifetime_spend
from orders
group by 1
),
joined as (
select customers.*,
customer_orders_summary.count_lifetime_orders,
customer_orders_summary.first_ordered_at,
customer_orders_summary.last_ordered_at,
customer_orders_summary.lifetime_spend_pretax,
customer_orders_summary.lifetime_tax_paid,
customer_orders_summary.lifetime_spend,
case
when customer_orders_summary.is_repeat_buyer then 'returning'
else 'new'
end as customer_type
from customers
left join customer_orders_summary on customers.customer_id = customer_orders_summary.customer_id
)
select *
from joined
6 changes: 6 additions & 0 deletions examples/jaffle_shop/marts/locations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with locations as (
select *
from stg_locations
)
select *
from locations
37 changes: 37 additions & 0 deletions examples/jaffle_shop/marts/order_items.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
with order_items as (
select *
from stg_order_items
),
orders as (
select *
from stg_orders
),
products as (
select *
from stg_products
),
supplies as (
select *
from 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.*,
orders.ordered_at,
products.product_name,
products.product_price,
products.is_food_item,
products.is_drink_item,
order_supplies_summary.supply_cost
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
50 changes: 50 additions & 0 deletions examples/jaffle_shop/marts/orders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
with orders as (
select *
from stg_orders
),
order_items_cte as (
select *
from order_items
),
order_items_summary as (
select order_id,
sum(supply_cost) as order_cost,
sum(product_price) as order_items_subtotal,
count(order_item_id) as count_order_items,
sum(
case
when is_food_item then 1
else 0
end
) as count_food_items,
sum(
case
when is_drink_item then 1
else 0
end
) as count_drink_items
from order_items_cte
group by 1
),
compute_booleans as (
select orders.*,
order_items_summary.order_cost,
order_items_summary.order_items_subtotal,
order_items_summary.count_food_items,
order_items_summary.count_drink_items,
order_items_summary.count_order_items,
order_items_summary.count_food_items > 0 as is_food_order,
order_items_summary.count_drink_items > 0 as is_drink_order
from orders
left join order_items_summary on orders.order_id = order_items_summary.order_id
),
customer_order_count as (
select *,
row_number() over (
partition by customer_id
order by ordered_at asc
) as customer_order_number
from compute_booleans
)
select *
from customer_order_count
6 changes: 6 additions & 0 deletions examples/jaffle_shop/marts/products.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with products as (
select *
from stg_products
)
select *
from products
6 changes: 6 additions & 0 deletions examples/jaffle_shop/marts/supplies.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with supplies as (
select *
from stg_supplies
)
select *
from supplies
Loading
Loading