Skip to content

Commit

Permalink
reorganize and add new models
Browse files Browse the repository at this point in the history
  • Loading branch information
Bethany Hipple committed Mar 14, 2024
1 parent b8a853d commit 7dc5c1e
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 23 deletions.
21 changes: 0 additions & 21 deletions analysis/stripe/stg_stripe__payment.sql

This file was deleted.

44 changes: 44 additions & 0 deletions models/marts/dim_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
with customers as (

select * from {{ ref('stg_jaffle_shop__customers') }}

),

orders as (

select * from {{ ref('stg_jaffle_shop__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

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

from customers

left join customer_orders using (customer_id)

)

select * from final
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
with events as (
select * from {# {{ ref('stg_snowplow__events') }} #}
select * from {{ ref('stg_snowplow__events') }}
),
page_views as (
select * from events
Expand Down
Empty file added models/marts/hhh-hh.sql
Empty file.
31 changes: 31 additions & 0 deletions models/staging/jaffle_shop/_schema_jaffle_shop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
models:
- name: stg_jaffle_shop__customers
columns:
- name: customer_id
tests:
- unique
- not_null
- name: stg_jaffle_shop__orders
columns:
- name: order_id
tests:
- unique
- not_null
- name: status
tests:
- accepted_values:
values:
- "returned"
- "completed"
- "pending"
- "placed"
- "shipped"
- name: stg_jaffle_shop__products
columns:
- name: sku
tests:
- unique:
config:
where: "product_type = 'jaffle'"

- not_null
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ sources:
database: raw
schema: jaffle_shop
tables:
- name: customers
- name: customers
- name: orders
- name: products
20 changes: 20 additions & 0 deletions models/staging/jaffle_shop/stg_jaffle_shop__customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
with

source as (

select * from {{ source('jaffle_shop', 'customers') }}

),

renamed as (

select
id as customer_id,
first_name,
last_name

from source

)

select * from renamed
22 changes: 22 additions & 0 deletions models/staging/jaffle_shop/stg_jaffle_shop__orders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with

source as (

select * from {{ source('jaffle_shop', 'orders') }}

),

renamed as (

select
id as order_id,
user_id as customer_id,
order_date,
status,
_etl_loaded_at

from source

)

select * from renamed
22 changes: 22 additions & 0 deletions models/staging/jaffle_shop/stg_jaffle_shop__products.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with

source as (

select * from {{ source('jaffle_shop', 'products') }}

),

renamed as (

select
sku,
name as product_name,
type as product_type,
description,
price

from source

)

select * from renamed
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ version: 2
sources:
- name: stripe
database: raw
schema: stripe
tables:
- name: payment
25 changes: 25 additions & 0 deletions models/staging/stripe/stg_stripe__payment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
with

source as (

select * from {{ source('stripe', 'payment') }}

),

renamed as (

select
amount,
created,
id,
orderid,
paymentmethod,
status,
_batched_at


from source

)

select * from renamed

0 comments on commit 7dc5c1e

Please sign in to comment.