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
70 changes: 70 additions & 0 deletions models/marts/core/dimensions/_dim_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: 2

models:
- name: dim_customers
description: Customer dimension with profile, contact, location, and segmentation attributes.
columns:
- name: customer_id
description: Unique customer identifier.
tests:
- unique
- not_null

- name: dim_employees
description: Employee dimension with profile, contact, employment, store, and compensation attributes.
columns:
- name: employee_id
description: Unique employee identifier.
tests:
- unique
- not_null

- name: dim_products
description: Product dimension with catalog, pricing, inventory status, supplier, and review summary attributes.
columns:
- name: product_id
description: Unique product identifier.
tests:
- unique
- not_null

- name: sku
description: Standardized product SKU.

- name: category
description: Standardized product category.

- name: dim_stores
description: Store dimension with profile, location, operations, and facility attributes.
columns:
- name: store_id
description: Unique store identifier.
tests:
- unique
- not_null

- name: region
description: Store operating region.

- name: is_active
description: Standardized active-store indicator.
tests:
- accepted_values:
arguments:
values: ['True', 'False', 'Unknown']

- name: dim_date
description: Calendar dimension built from dates observed across sales, returns, reviews, and inventory snapshots.
columns:
- name: date_day
description: Calendar date.
tests:
- unique
- not_null

- name: day_type
description: Weekday or weekend indicator.
tests:
- accepted_values:
arguments:
values: ['Weekday', 'Weekend']
31 changes: 31 additions & 0 deletions models/marts/core/dimensions/dim_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
SELECT
p.customer_id,
TRIM(CONCAT(p.title, ' ', p.first_name, ' ', p.last_name)) as customer_name,
p.gender,
p.date_of_birth,
c.email,
c.phone,
l.address,
l.zip_code,
l.city,
l.region,
l.state,
l.state_abbr,
l.country,
s.company,
s.customer_segment,
c.preferred_channel,
s.is_active,
s.loyalty_points,
s.annual_income_usd,
s.account_created_date
FROM {{ ref('int_customer_profile') }} as p

LEFT JOIN {{ ref('int_customers_contact') }} as c
ON p.customer_id = c.customer_id

LEFT JOIN {{ ref('int_customer_location') }} as l
ON p.customer_id = l.customer_id

LEFT JOIN {{ ref('int_customer_segmentation') }} as s
ON s.customer_id = p.customer_id ;
30 changes: 30 additions & 0 deletions models/marts/core/dimensions/dim_date.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
WITH dates AS (
SELECT order_date AS date_day FROM {{ ref('int_transaction_fulfillment') }}
UNION
SELECT ship_date AS date_day FROM {{ ref('int_transaction_fulfillment') }}
UNION
SELECT delivery_date AS date_day FROM {{ ref('int_transaction_fulfillment') }}
UNION
SELECT return_date AS date_day FROM {{ ref('int_return_transaction') }}
UNION
SELECT review_date AS date_day FROM {{ ref('int_review_transaction') }}
UNION
SELECT snapshot_date AS date_day FROM {{ ref('int_inventory_product') }}
)

SELECT
date_day,
YEAR(date_day) AS year_number,
DATEPART(QUARTER, date_day) AS quarter_number,
MONTH(date_day) AS month_number,
DATENAME(MONTH, date_day) AS month_name,
DAY(date_day) AS day_of_month,
DATEPART(WEEK, date_day) AS week_number,
DATENAME(WEEKDAY, date_day) AS day_name,
DATEPART(WEEKDAY, date_day) AS day_of_week_number,
CASE
WHEN DATEPART(WEEKDAY, date_day) IN (1, 7) THEN 'Weekend'
ELSE 'Weekday'
END AS day_type
FROM dates
WHERE date_day IS NOT NULL;
24 changes: 24 additions & 0 deletions models/marts/core/dimensions/dim_employees.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SELECT
p.employee_id,
e.store_id,
e.manager_id,
CONCAT(p.first_name, ' ', p.last_name) as employee_name,
e.job_title,
e.department,
e.performance_rating,
e.store_name,
e.store_city,
c.email,
c.phone,
e.annual_salary_usd,
e.commission_rate_pct,
e.years_employed,
e.is_active,
p.hire_date
FROM {{ ref('int_employee_profile') }} as p

LEFT JOIN {{ ref('int_employee_contact') }} as c
ON p.employee_id = c.employee_id

LEFT JOIN {{ ref('int_employee_employment') }} as e
ON p.employee_id = e.employee_id ;
Empty file.
30 changes: 30 additions & 0 deletions models/marts/core/dimensions/dim_products.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
SELECT
a.product_id,
a.sku,
a.product_name,
a.brand,
a.category,
a.sub_category,
a.department,
a.launched_date,
a.product_url,
p.base_price_usd,
p.cost_price_usd,
p.gross_margin_pct,
i.is_available,
i.stock_quantity,
i.reorder_level,
s.supplier_name,
s.supplier_country,
s.weight_kg,
s.warranty_years,
s.rating_avg,
s.review_count
FROM {{ ref('int_product_attributes') }} AS a
LEFT JOIN {{ ref('int_product_pricing') }} AS p
ON a.product_id = p.product_id
LEFT JOIN {{ ref('int_product_inventory') }} AS i
ON a.product_id = i.product_id
LEFT JOIN {{ ref('int_product_supplier') }} AS s
ON a.product_id = s.product_id
WHERE a.product_id IS NOT NULL;
27 changes: 27 additions & 0 deletions models/marts/core/dimensions/dim_stores.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SELECT
p.store_id,
p.store_name,
p.store_type,
p.manager_name,
p.opened_date,
l.address,
l.city,
l.state,
l.state_full,
l.zip_code,
l.country,
l.region,
l.district,
l.phone,
o.sq_footage,
o.num_employees,
o.annual_rent_usd,
o.is_active,
o.has_parking,
o.has_cafe
FROM {{ ref('int_store_profile') }} AS p
LEFT JOIN {{ ref('int_store_location') }} AS l
ON p.store_id = l.store_id
LEFT JOIN {{ ref('int_store_operations') }} AS o
ON p.store_id = o.store_id
WHERE p.store_id IS NOT NULL;
Loading