Skip to content

Commit

Permalink
Commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Fajardo committed Dec 5, 2024
1 parent 419f358 commit 961a243
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 102 deletions.
53 changes: 0 additions & 53 deletions models/_samples/staging/jaffle_shop/stg_jaffle_shop__customers.sql

This file was deleted.

48 changes: 0 additions & 48 deletions models/_samples/staging/jaffle_shop/stg_jaffle_shop__orders.sql

This file was deleted.

15 changes: 15 additions & 0 deletions models/semantic_layer_demo/_semantic_layer_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2

sources:
- name: orders
database: raw
schema: jaffle_shop
tables:
- name: orders
- name: customers

- name: payments
database: raw
schema: stripe
tables:
- name: payment
29 changes: 29 additions & 0 deletions models/semantic_layer_demo/marts/dim_customer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
with customers as (
select * from {{ ref('stg_jaffle_shop__customers')}}
),
orders as (
select * from {{ ref('fact_orders')}}
),
customer_orders as (
select
customer_id,
min(order_date) as first_order_date,
max(order_date) as most_recent_order_date,
count(order_id) as number_of_orders,
sum(amount) as lifetime_value
from orders
group by 1
),
final as (
select
customers.customer_id,
customers.first_name,
customers.last_name,
customer_orders.first_order_date,
customer_orders.most_recent_order_date,
coalesce(customer_orders.number_of_orders, 0) as number_of_orders,
customer_orders.lifetime_value
from customers
left join customer_orders using (customer_id)
)
select * from final
43 changes: 43 additions & 0 deletions models/semantic_layer_demo/marts/fact_orders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{
config(
tags=["semantic_layer_demo"]
)
}}

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


payments as (
select * from {{ ref('stg_stripe__payment') }}
),


order_payments as (
select
order_id,
sum(case when status = 'success' then amount end) as amount


from payments
group by 1
),


final as (


select
orders.order_id,
orders.customer_id,
orders.order_date,
coalesce(order_payments.amount, 0) as amount


from orders
left join order_payments using (order_id)
)


select * from final
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{
config(
tags=['semantic_layer_demo']
)
}}

select
id as customer_id,
first_name,
last_name
from {{ source('jaffle_shop', 'customers') }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{
config(
tags=['semantic_layer_demo']
)
}}

select
id as order_id,
user_id as customer_id,
order_date,
status
from {{ source('jaffle_shop', 'orders') }}
17 changes: 17 additions & 0 deletions models/semantic_layer_demo/staging/stripe/stg_stripe__payment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{
config(
tags=['semantic_layer_demo']
)
}}

select
id as payment_id,
orderid as order_id,
paymentmethod as payment_method,
status,
-- amount is stored in cents, convert it to dollars
amount / 100 as amount,
created as created_at


from {{ source('stripe', 'payment') }}
2 changes: 1 addition & 1 deletion models/staging/stripe/stg_stripe__payments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ select
-- datetimes
created as created_at

from {{ ref('snapshot_stg_payments') }}
from {{ source('stripe', 'payment') }}
-- pull only the most recent update for each unique record
where dbt_valid_to is null

0 comments on commit 961a243

Please sign in to comment.