-
Notifications
You must be signed in to change notification settings - Fork 15
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
Keith Fajardo
committed
Dec 5, 2024
1 parent
419f358
commit 961a243
Showing
11 changed files
with
128 additions
and
102 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
models/_samples/staging/jaffle_shop/stg_jaffle_shop__customers.sql
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
models/_samples/staging/jaffle_shop/stg_jaffle_shop__orders.sql
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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 |
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
models/semantic_layer_demo/staging/jaffle_shop/stg_jaffle_shop__customers.sql
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
tags=['semantic_layer_demo'] | ||
) | ||
}} | ||
|
||
select | ||
id as customer_id, | ||
first_name, | ||
last_name | ||
from {{ source('jaffle_shop', 'customers') }} |
12 changes: 12 additions & 0 deletions
12
models/semantic_layer_demo/staging/jaffle_shop/stg_jaffle_shop__orders.sql
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 |
---|---|---|
@@ -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
17
models/semantic_layer_demo/staging/stripe/stg_stripe__payment.sql
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 |
---|---|---|
@@ -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') }} |
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