Skip to content

Commit 0e92d69

Browse files
Merge pull request #30 from Ritik574-coder/dbt_branch
adding mart model and defining the dimantion models
2 parents 18d6545 + cfab46b commit 0e92d69

7 files changed

Lines changed: 212 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
version: 2
2+
3+
models:
4+
- name: dim_customers
5+
description: Customer dimension with profile, contact, location, and segmentation attributes.
6+
columns:
7+
- name: customer_id
8+
description: Unique customer identifier.
9+
tests:
10+
- unique
11+
- not_null
12+
13+
- name: dim_employees
14+
description: Employee dimension with profile, contact, employment, store, and compensation attributes.
15+
columns:
16+
- name: employee_id
17+
description: Unique employee identifier.
18+
tests:
19+
- unique
20+
- not_null
21+
22+
- name: dim_products
23+
description: Product dimension with catalog, pricing, inventory status, supplier, and review summary attributes.
24+
columns:
25+
- name: product_id
26+
description: Unique product identifier.
27+
tests:
28+
- unique
29+
- not_null
30+
31+
- name: sku
32+
description: Standardized product SKU.
33+
34+
- name: category
35+
description: Standardized product category.
36+
37+
- name: dim_stores
38+
description: Store dimension with profile, location, operations, and facility attributes.
39+
columns:
40+
- name: store_id
41+
description: Unique store identifier.
42+
tests:
43+
- unique
44+
- not_null
45+
46+
- name: region
47+
description: Store operating region.
48+
49+
- name: is_active
50+
description: Standardized active-store indicator.
51+
tests:
52+
- accepted_values:
53+
arguments:
54+
values: ['True', 'False', 'Unknown']
55+
56+
- name: dim_date
57+
description: Calendar dimension built from dates observed across sales, returns, reviews, and inventory snapshots.
58+
columns:
59+
- name: date_day
60+
description: Calendar date.
61+
tests:
62+
- unique
63+
- not_null
64+
65+
- name: day_type
66+
description: Weekday or weekend indicator.
67+
tests:
68+
- accepted_values:
69+
arguments:
70+
values: ['Weekday', 'Weekend']
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
SELECT
2+
p.customer_id,
3+
TRIM(CONCAT(p.title, ' ', p.first_name, ' ', p.last_name)) as customer_name,
4+
p.gender,
5+
p.date_of_birth,
6+
c.email,
7+
c.phone,
8+
l.address,
9+
l.zip_code,
10+
l.city,
11+
l.region,
12+
l.state,
13+
l.state_abbr,
14+
l.country,
15+
s.company,
16+
s.customer_segment,
17+
c.preferred_channel,
18+
s.is_active,
19+
s.loyalty_points,
20+
s.annual_income_usd,
21+
s.account_created_date
22+
FROM {{ ref('int_customer_profile') }} as p
23+
24+
LEFT JOIN {{ ref('int_customers_contact') }} as c
25+
ON p.customer_id = c.customer_id
26+
27+
LEFT JOIN {{ ref('int_customer_location') }} as l
28+
ON p.customer_id = l.customer_id
29+
30+
LEFT JOIN {{ ref('int_customer_segmentation') }} as s
31+
ON s.customer_id = p.customer_id ;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
WITH dates AS (
2+
SELECT order_date AS date_day FROM {{ ref('int_transaction_fulfillment') }}
3+
UNION
4+
SELECT ship_date AS date_day FROM {{ ref('int_transaction_fulfillment') }}
5+
UNION
6+
SELECT delivery_date AS date_day FROM {{ ref('int_transaction_fulfillment') }}
7+
UNION
8+
SELECT return_date AS date_day FROM {{ ref('int_return_transaction') }}
9+
UNION
10+
SELECT review_date AS date_day FROM {{ ref('int_review_transaction') }}
11+
UNION
12+
SELECT snapshot_date AS date_day FROM {{ ref('int_inventory_product') }}
13+
)
14+
15+
SELECT
16+
date_day,
17+
YEAR(date_day) AS year_number,
18+
DATEPART(QUARTER, date_day) AS quarter_number,
19+
MONTH(date_day) AS month_number,
20+
DATENAME(MONTH, date_day) AS month_name,
21+
DAY(date_day) AS day_of_month,
22+
DATEPART(WEEK, date_day) AS week_number,
23+
DATENAME(WEEKDAY, date_day) AS day_name,
24+
DATEPART(WEEKDAY, date_day) AS day_of_week_number,
25+
CASE
26+
WHEN DATEPART(WEEKDAY, date_day) IN (1, 7) THEN 'Weekend'
27+
ELSE 'Weekday'
28+
END AS day_type
29+
FROM dates
30+
WHERE date_day IS NOT NULL;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
SELECT
2+
p.employee_id,
3+
e.store_id,
4+
e.manager_id,
5+
CONCAT(p.first_name, ' ', p.last_name) as employee_name,
6+
e.job_title,
7+
e.department,
8+
e.performance_rating,
9+
e.store_name,
10+
e.store_city,
11+
c.email,
12+
c.phone,
13+
e.annual_salary_usd,
14+
e.commission_rate_pct,
15+
e.years_employed,
16+
e.is_active,
17+
p.hire_date
18+
FROM {{ ref('int_employee_profile') }} as p
19+
20+
LEFT JOIN {{ ref('int_employee_contact') }} as c
21+
ON p.employee_id = c.employee_id
22+
23+
LEFT JOIN {{ ref('int_employee_employment') }} as e
24+
ON p.employee_id = e.employee_id ;

models/marts/core/dimensions/dim_inventory.sql

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
SELECT
2+
a.product_id,
3+
a.sku,
4+
a.product_name,
5+
a.brand,
6+
a.category,
7+
a.sub_category,
8+
a.department,
9+
a.launched_date,
10+
a.product_url,
11+
p.base_price_usd,
12+
p.cost_price_usd,
13+
p.gross_margin_pct,
14+
i.is_available,
15+
i.stock_quantity,
16+
i.reorder_level,
17+
s.supplier_name,
18+
s.supplier_country,
19+
s.weight_kg,
20+
s.warranty_years,
21+
s.rating_avg,
22+
s.review_count
23+
FROM {{ ref('int_product_attributes') }} AS a
24+
LEFT JOIN {{ ref('int_product_pricing') }} AS p
25+
ON a.product_id = p.product_id
26+
LEFT JOIN {{ ref('int_product_inventory') }} AS i
27+
ON a.product_id = i.product_id
28+
LEFT JOIN {{ ref('int_product_supplier') }} AS s
29+
ON a.product_id = s.product_id
30+
WHERE a.product_id IS NOT NULL;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
SELECT
2+
p.store_id,
3+
p.store_name,
4+
p.store_type,
5+
p.manager_name,
6+
p.opened_date,
7+
l.address,
8+
l.city,
9+
l.state,
10+
l.state_full,
11+
l.zip_code,
12+
l.country,
13+
l.region,
14+
l.district,
15+
l.phone,
16+
o.sq_footage,
17+
o.num_employees,
18+
o.annual_rent_usd,
19+
o.is_active,
20+
o.has_parking,
21+
o.has_cafe
22+
FROM {{ ref('int_store_profile') }} AS p
23+
LEFT JOIN {{ ref('int_store_location') }} AS l
24+
ON p.store_id = l.store_id
25+
LEFT JOIN {{ ref('int_store_operations') }} AS o
26+
ON p.store_id = o.store_id
27+
WHERE p.store_id IS NOT NULL;

0 commit comments

Comments
 (0)