Skip to content

Commit 18d6545

Browse files
Merge pull request #29 from Ritik574-coder/dbt_branch
feat(intermediate): architect transactional silver layer firewalls with multi-locale parsing and defensive metrics bounding
2 parents c046657 + c421595 commit 18d6545

6 files changed

Lines changed: 705 additions & 2 deletions

File tree

models/intermediate/Employees/_int_employees_models.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
version: 2
42
models:
53

@@ -125,6 +123,10 @@ models:
125123
the source value into a standard `INT`. If the raw entry is non-numeric (fails parsing) OR
126124
is a negative integer (physically impossible for our enterprise sequence), the model coerces
127125
the result to `NULL`. This completely eliminates downstream foreign key join failures.
126+
tests:
127+
- relationships:
128+
to: ref('int_store_profile')
129+
field: store_id
128130

129131
- name: store_name
130132
description: |

models/intermediate/Inventory/_int_inventory_models.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ models:
3535
or missing values are safely coerced to NULL to prevent downstream join failures.
3636
tests:
3737
- not_null
38+
- relationships:
39+
to: ref('int_product_attributes')
40+
field: product_id
3841

3942
- name: product_name
4043
description: |
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
version: 2
2+
3+
models:
4+
####################################################################################
5+
####################### Model: int_return_processing ###############################
6+
####################################################################################
7+
- name: int_return_processing
8+
description: |
9+
Creates a trusted return processing operational dataset by standardizing categorical metrics,
10+
normalizing return fulfillment channels, and cleansing workflow status identifiers. The model
11+
applies Title Case to reason fields and handles alphanumeric casting exceptions for logistics personnel.
12+
13+
columns:
14+
- name: return_id
15+
description: Primary key uniquely identifying the individual return log.
16+
tests:
17+
- unique
18+
- not_null
19+
20+
- name: return_reason
21+
description: |
22+
The documented customer reason for returning the product.
23+
**Transformation Logic:** Standardized using whitespace trimming and converted to Title Case. Missing or empty string inputs fallback to 'Unknown'.
24+
tests:
25+
- not_null
26+
27+
- name: return_channel
28+
description: |
29+
The operational channel through which the return was initiated.
30+
**Transformation Logic:** Groups highly fragmented text inputs into specific corporate categories:
31+
- 'Mobile App' (Mapped from: 'app', 'mobile app', 'mobile')
32+
- 'In Store' (Mapped from: 'in store', 'in-store', 'store')
33+
- 'Online' (Mapped from: 'online', 'web')
34+
- 'Phone Call' (Mapped from: 'phone')
35+
- 'Catalog' (Mapped from: 'catalog')
36+
- Unmapped formats default to 'Unknown'.
37+
tests:
38+
- not_null
39+
- accepted_values:
40+
arguments:
41+
values: ['Mobile App', 'In Store', 'Online', 'Phone Call', 'Catalog', 'Unknown']
42+
43+
- name: restocked
44+
description: |
45+
Operational flag indicating whether the item was returned to store inventory shelf space.
46+
**Transformation Logic:** Standardized from multi-type strings ('yes', 'y', '1' to 'Yes' / 'no', 'n', '0' to 'No'). Outliers resolve to 'Unknown'.
47+
tests:
48+
- not_null
49+
- accepted_values:
50+
arguments:
51+
values: ['Yes', 'No', 'Unknown']
52+
53+
- name: return_status
54+
description: |
55+
Current state of the return processing lifecycle. Standardized to Title Case; missing source entries default to 'Unknown'.
56+
tests:
57+
- not_null
58+
59+
- name: handled_by_emp_id
60+
description: |
61+
The unique identifier of the store employee processing the return ticket. Converted to an integer data type, with missing or invalid fields coerced to NULL.
62+
63+
####################################################################################
64+
####################### Model: int_return_refund ###################################
65+
####################################################################################
66+
- name: int_return_refund
67+
description: |
68+
Extracts and sanitizes financial reimbursement attributes for returned orders. The model programmatically
69+
scrubs text currency strings to isolate decimals and normalizes payment methods to support precise gross margin
70+
reconciliation tracking.
71+
72+
columns:
73+
- name: return_id
74+
description: Unique primary key mapping to the corresponding return entry.
75+
tests:
76+
- unique
77+
- not_null
78+
79+
- name: refund_amount
80+
description: |
81+
The total dollar value reimbursed back to the customer, cast to decimal(10,2) precision.
82+
**Transformation Logic:** Strips formatting artifacts including currency symbols ('$') and thousands separators (',') before typecasting. Negative entries or un-castable formats default to NULL.
83+
84+
- name: refund_method
85+
description: |
86+
The transaction payment type used for the reimbursement (e.g., Credit Card, Cash). Standardized using Title Case, defaulting blank rows to 'Unknown'.
87+
tests:
88+
- not_null
89+
- accepted_values:
90+
arguments:
91+
values:
92+
- Cash
93+
- Original Payment
94+
- Store Credit
95+
96+
####################################################################################
97+
####################### Model: int_return_transaction ##############################
98+
####################################################################################
99+
- name: int_return_transaction
100+
description: |
101+
Normalizes and links return vouchers back to their core original transaction entities. The model enforces
102+
prefix patterns for tracking codes, tokenizes associated consumer profile fields into Title Case, and
103+
executes a multi-locale temporal handling sequence to cast multi-format text values into clean ISO dates.
104+
105+
columns:
106+
- name: return_id
107+
description: Cleaned primary identification key. Values below 1 or non-numeric elements resolve to NULL.
108+
tests:
109+
- unique
110+
- not_null
111+
112+
- name: original_txn_id
113+
description: |
114+
The alphanumeric string of the original purchasing transaction header.
115+
**Transformation Logic:** Enforces strict systemic syntax verification: must contain the
116+
corporate prefix 'TXN-' and maintain a minimum character length of 10. Failing rows are coerced to NULL.
117+
118+
- name: original_order_id
119+
description: The integer identifier tracking the master order entry. Values below 1 or invalid formats resolve to NULL.
120+
121+
- name: customer_id
122+
description: Unique identifier linking the transaction to a customer account profile. Invalid formats resolve to NULL.
123+
124+
- name: customer_name
125+
description: Full name of the purchasing client. Standardized into Title Case; blank inputs fallback to 'Unknown'.
126+
tests:
127+
- not_null
128+
129+
- name: product_id
130+
description: Unique identifier tracking the specific physical item returned. Invalid formats resolve to NULL.
131+
132+
- name: product_name
133+
description: Official description name of the item. Standardized into Title Case; blanks default to 'Unknown'.
134+
tests:
135+
- not_null
136+
137+
- name: quantity_returned
138+
description: |
139+
Total count of physical units returned. Enforces business rule threshold :
140+
values below 1 or non-numeric elements are coerced to NULL.
141+
142+
- name: return_date
143+
description: |
144+
The calendar date the return was officially recorded by the system.
145+
**Transformation Logic:** Evaluates multiple text structures into an ISO-standard DATE format via an explicit CASE validation tree:
146+
- Textual month lines and standard hyphen/slash paths are natively parsed.
147+
- Multi-locale ambiguity is handled defensively: if the middle token exceeds 12, it is treated as US format (Style 101);
148+
if the leading segment exceeds 12, it is handled as International format (Style 103).
149+
tests:
150+
- not_null
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
version: 2
2+
3+
models:
4+
####################################################################################
5+
####################### Model: int_review_feedback #################################
6+
####################################################################################
7+
- name: int_review_feedback
8+
description: |
9+
Creates a trusted product review metadata dataset by standardizing submission channels
10+
and cleansing text field values. The model normalizes user engagement attributes,
11+
strips carriage returns and line breaks from titles using scalar operations, and maps
12+
highly fragmented input strings into canonical omni-channel tracking vectors.
13+
14+
columns:
15+
- name: review_id
16+
description: Primary key uniquely identifying the consumer review record.
17+
tests:
18+
- unique
19+
- not_null
20+
21+
- name: helpful_votes
22+
description: The total volume of user votes marking the review as informative.
23+
24+
- name: review_channel
25+
description: |
26+
The unified front-end channel where the submission was published.
27+
**Transformation Logic:** Groups variations and shortcuts into a Title Case business taxonomy:
28+
- 'Mobile App' (From: 'app', 'mobile app', 'mobile')
29+
- 'In Store' (From: 'in store', 'in-store', 'store')
30+
- 'Online' (From: 'online', 'web')
31+
- 'Phone Call' (From: 'phone')
32+
- 'Catalog' (From: 'catalog')
33+
- Missing or unmapped structures safely default to 'Unknown'.
34+
tests:
35+
- not_null
36+
- accepted_values:
37+
arguments:
38+
values: ['Mobile App', 'In Store', 'Online', 'Phone Call', 'Catalog', 'Unknown']
39+
40+
- name: review_title
41+
description: |
42+
The sanitized summary title text.
43+
**Transformation Logic:** Applies whitespace trimming, Title Case conversions, and strips
44+
hidden carriage returns `CHAR(13)` and line feeds `CHAR(10)`. Empty fields default to 'Unknown'.
45+
tests:
46+
- not_null
47+
48+
####################################################################################
49+
####################### Model: int_review_rating ###################################
50+
####################################################################################
51+
- name: int_review_rating
52+
description: |
53+
Processes customer review scores by implementing defensive type-casting and explicit boundary validation.
54+
The model protects downstream aggregate scoring matrices (such as Average Rating Score) by
55+
filtering out out-of-bounds ratings and corrupted text responses.
56+
57+
columns:
58+
- name: review_id
59+
description: Primary key matching back to the master feedback dimension.
60+
tests:
61+
- unique
62+
- not_null
63+
64+
- name: rating
65+
description: |
66+
The validated numerical assessment score assigned by the consumer.
67+
**Transformation Logic:** Casts the source string to an integer. Enforces a strict business boundary:
68+
values MUST sit between 1 and 5 inclusive. Any values outside this target scale default to NULL.
69+
tests:
70+
- accepted_values:
71+
arguments:
72+
values: [1, 2, 3, 4, 5]
73+
74+
- name: rating_text
75+
description: The raw textual comment or contextual feedback submitted along with the rating score.
76+
77+
####################################################################################
78+
####################### Model: int_review_transaction ##############################
79+
####################################################################################
80+
- name: int_review_transaction
81+
description: |
82+
Normalizes and connects product review headers back to their original purchasing transactions,
83+
consumer accounts, and items. The model processes temporal values through a multi-locale validation
84+
ladder to convert multi-format text values into immutable ISO-standard dates.
85+
86+
columns:
87+
- name: review_id
88+
description: Primary key uniquely identifying the review transaction bridge.
89+
tests:
90+
- unique
91+
- not_null
92+
93+
- name: txn_id
94+
description: Foreign key mapping the review back to the source point-of-sale transaction record.
95+
tests:
96+
- not_null
97+
98+
- name: customer_id
99+
description: Foreign key linking to the corresponding customer entity profile.
100+
tests:
101+
- not_null
102+
103+
- name: customer_name
104+
description: The full identity string of the purchasing customer.
105+
106+
- name: product_id
107+
description: Foreign key linking to the corresponding product master record.
108+
tests:
109+
- not_null
110+
111+
- name: product_name
112+
description: Cleaned retail name nomenclature of the item reviewed.
113+
114+
- name: review_date
115+
description: |
116+
The standardized calendar logging date when the review was written.
117+
**Transformation Logic:** Converts multi-format text entries into a safe DATE data type via an explicit CASE validation tree:
118+
- Abbreviated or full textual month variations and standard ISO hyphen/slash paths are natively parsed.
119+
- Date ambiguity is handled defensively: if the middle segment exceeds 12, it is treated as US format (Style 101/110).
120+
If the leading segment exceeds 12, it is handled as International format (Style 103/105).
121+
tests:
122+
- not_null

0 commit comments

Comments
 (0)