You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: refactor pipeline documentation to design-contract architecture
- Decoupled stage Executor and Logic into distinct contracts
- Map component-level failure surfaces and severity models
- Align Global Orchestrator docstrings with the Promote-Purge-Restore Cloud-Sync pattern
**Role:** Data Integration and Analytical Flattening.
8
+
9
+
## **System Contract**
10
+
11
+
**Purpose**
12
+
13
+
Integrates multiple normalized relational tables into a unified, analytical "Event" dataset and extracts high-fidelity "Dimension" references. It transforms raw business facts into a ready-to-model state by enforcing cardinality rules and calculating temporal performance metrics.
14
+
15
+
**Invariants**
16
+
***Strict Order-ID Grain:** The primary event output is guaranteed to be exactly 1 row per `order_id`. Any operation causing cardinality explosion triggers a terminal failure.
17
+
***Inner-Join Priority:** To maintain analytical integrity, orders without corresponding items are purged.
18
+
***Temporal Determinism:** All lead times, lags, and delays are calculated as integer-day durations based on validated UTC timestamps.
19
+
***Reference Uniqueness:** Dimension reference tables (Customers, Products) are strictly deduplicated by their primary keys.
20
+
21
+
**Inputs**
22
+
*`run_context`: `RunContext` (Path resolution for Silver/contracted and Gold/assembled zones).
23
+
***Source Tables:**`df_orders`, `df_order_items`, `df_payments` (from the contracted layer).
24
+
25
+
**Outputs**
26
+
***Assembly Report:**`dict` (Step-level status and informational logs).
27
+
***Assembled Events:**`parquet` (The unified analytical order-grain table).
28
+
***Dimension Refs:**`parquet` (Unique snapshots of customer and product attributes).
29
+
30
+
## **Execution Workflow**
31
+
32
+
The **Executor** coordinates two distinct sub-orchestrations:
33
+
34
+
### **Workflow I: Event Assembly**
35
+
1.**Batch Load:** Fetches the required triplet (`orders`, `items`, `payments`) from the Silver zone.
36
+
2.**Merge:** Joins datasets using `merge_data`. It performs an inner join on items and a left join on payments to preserve financial data without losing order context.
37
+
3.**Derivation:** Executes `derive_fields` to calculate fulfillment lead times and extract ISO-calendar attributes.
38
+
4.**Schema Freeze:** Projects the final `ASSEMBLE_SCHEMA` and casts all columns to `ASSEMBLE_DTYPES`.
39
+
5.**Export & Clean:** Persists the table and triggers `gc.collect()` to free memory before dimension processing.
| Enforce 1:1 cardinality for the final event grain. | Handle schema validation of raw data. |
53
+
| Deduplicate dimension attributes. | Manage partitioning logic (managed by the loader/exporter). |
54
+
| Manage peak memory via explicit `gc` triggers. | Change historical values or re-map IDs. |
55
+
56
+
## **Failure & Severity Model**
57
+
58
+
### **Operational Failures (System Level)**
59
+
***Loading Missing Table:** If a required table (e.g., `df_orders`) is missing from the Silver zone, the stage returns `failed` immediately.
60
+
***Export Failure:** Disk I/O errors or path resolution issues during the `export_file` call halt the lifecycle.
61
+
62
+
### **Functional Findings (Data Level)**
63
+
64
+
***Cardinality Explosion:** If `merge_data` detects multiple rows for a single `order_id`, it raises a `RuntimeError`, treating it as a fatal violation of the analytical grain.
65
+
***Reference Duplication:** If a dimension table contains duplicate primary keys after extraction, it raises a `RuntimeError` to prevent downstream join corruption.
66
+
***Partial Payments:** Orders without payments are allowed (via Left Join); the system fills these with `None/NaN`, which is considered a valid business state rather than a failure.
0 commit comments