Skip to content

Refactor Customers Model: Convert CTEs into Intermediate Models#2

Open
even-wei wants to merge 1 commit intomainfrom
refactor/customers-cte-to-models
Open

Refactor Customers Model: Convert CTEs into Intermediate Models#2
even-wei wants to merge 1 commit intomainfrom
refactor/customers-cte-to-models

Conversation

@even-wei
Copy link
Collaborator

Overview:
Refactored the customers model by turning two CTEs into intermediate models, enhancing readability and maintainability.

Changes:

  • Created two new intermediate models from existing CTEs.
  • Updated customers model to integrate these models.
  • Conducted code cleanup for efficiency.

Rationale:
Improves clarity and allows easier future modifications.

Testing:
Ensured accuracy and consistency in results post-refactor.

Review Request:
Feedback on the implementation and integration of the new models is welcomed.

@kentwelcome kentwelcome force-pushed the refactor/customers-cte-to-models branch from 989057f to 21de9d2 Compare March 28, 2024 08:45
@kentwelcome kentwelcome force-pushed the refactor/customers-cte-to-models branch from 21de9d2 to a48228a Compare April 26, 2024 08:53
@github-actions

This comment was marked as outdated.

@DataRecce DataRecce deleted a comment from github-actions bot Apr 26, 2024
@popcornylu popcornylu force-pushed the refactor/customers-cte-to-models branch from a48228a to 24411d3 Compare May 29, 2024 06:02
@github-actions

This comment was marked as outdated.

@popcornylu popcornylu force-pushed the refactor/customers-cte-to-models branch from 24411d3 to e639327 Compare May 30, 2024 09:52
@github-actions

This comment was marked as outdated.

@popcornylu popcornylu force-pushed the refactor/customers-cte-to-models branch from e639327 to 0b8e642 Compare June 5, 2024 08:22
@github-actions

This comment was marked as outdated.

@kentwelcome kentwelcome force-pushed the refactor/customers-cte-to-models branch 2 times, most recently from 0a2188b to a4dd026 Compare June 6, 2024 18:30
@wcchang1115 wcchang1115 force-pushed the refactor/customers-cte-to-models branch 2 times, most recently from 4509780 to 4248a98 Compare June 20, 2024 03:44
@wcchang1115 wcchang1115 force-pushed the refactor/customers-cte-to-models branch from 4248a98 to e4ee394 Compare July 4, 2024 10:31
@kentwelcome kentwelcome force-pushed the refactor/customers-cte-to-models branch from e4ee394 to e23db56 Compare July 9, 2024 07:29
@wcchang1115 wcchang1115 force-pushed the refactor/customers-cte-to-models branch from e23db56 to e4ee394 Compare August 14, 2024 02:01
@kentwelcome kentwelcome force-pushed the refactor/customers-cte-to-models branch from e4ee394 to 6d4ed11 Compare September 20, 2024 09:04
@even-wei even-wei force-pushed the refactor/customers-cte-to-models branch from 6d4ed11 to 5dc50e1 Compare October 21, 2024 02:28
@wcchang1115 wcchang1115 force-pushed the refactor/customers-cte-to-models branch from 5dc50e1 to 70151fe Compare October 24, 2024 03:44
Signed-off-by: Even Wei <shinycockorach@gmail.com>
@even-wei even-wei force-pushed the refactor/customers-cte-to-models branch from 70151fe to ae474ce Compare October 29, 2024 05:06
@popcornylu

This comment was marked as duplicate.

@recce-cloud
Copy link

recce-cloud bot commented Feb 28, 2026

Summary

PR #2 refactors the customers model by extracting two CTEs into intermediate models (int_customer_orders and int_customer_payments), improving code maintainability without altering data. Row count comparison shows the customers table remains stable at 1,856 records, and all 4 configured validation checks passed with 100% data accuracy. Two downstream models (customer_order_pattern, customer_segments) are flagged for verification due to dependency changes, though no breaking changes were detected.


Key Changes

  • Lineage refactoring: lineage_diff reveals 2 new intermediate models added to the dependency graph
  • Code simplification: customers model reduced from 69 lines to a cleaner implementation (52-line net reduction)
  • Row count stability: row_count_diff confirms customers maintained 1,856 records (0% change), orders stable at 280,844 records
  • Schema integrity: schema_diff detected 0 column changes - all 8 columns remain structurally identical
  • Data consistency: profile_diff on customers shows all column metrics identical (min/max/avg/distinct values unchanged across 8 columns)

Impact Analysis

graph LR
    stg_orders["stg_orders<br/>(view)"]:::unchanged
    stg_customers["stg_customers<br/>(view)"]:::unchanged
    stg_payments["stg_payments<br/>(view)"]:::unchanged
    customers["customers<br/>(table)"]:::modified
    customer_order_pattern["customer_order_pattern<br/>(table)"]:::impacted
    customer_segments["customer_segments<br/>(table)"]:::impacted
    int_customer_payments["int_customer_payments<br/>(table)"]:::added
    int_customer_orders["int_customer_orders<br/>(table)"]:::added

    stg_customers --> customers
    int_customer_orders --> customers
    int_customer_payments --> customers
    customers --> customer_order_pattern
    customers --> customer_segments
    stg_orders --> int_customer_payments
    stg_payments --> int_customer_payments
    stg_orders --> int_customer_orders

    classDef added fill:#d4edda,stroke:#28a745,color:#000000
    classDef removed fill:#f8d7da,stroke:#dc3545,color:#000000
    classDef modified fill:#fff3cd,stroke:#ffc107,color:#000000
    classDef impacted fill:#ffffff,stroke:#ffc107,color:#000000
    classDef unchanged fill:#ffffff,stroke:#d3d3d3,color:#999999
Loading
  • New models successfully created: int_customer_orders and int_customer_payments both populated with 1,856 records (matching customers table cardinality)
  • ⚠️ 2 downstream models impacted: customer_order_pattern and customer_segments depend on modified customers model - require validation that calculations remain correct
  • Upstream dependencies stable: stg_orders, stg_customers, and stg_payments unchanged, supporting both new intermediates and modified parent
  • 📝 Refactoring isolated to customers layer: No impact on production fact tables (orders stable at 280,844 records)

☑️ Checklist

All checks configured in the PR validation suite have been executed:

Name Run Status Impact Analysis
Query Diff of Customers Avg Lifetime Value ✅ PASS Weekly average customer lifetime values match perfectly across 98 weeks - no query logic degradation
Row Count of Customers, Orders and Modified Table Models ✅ PASS customers: 1,856 → 1,856 (0% change); orders: 280,844 → 280,844 (stable); new models: 1,856 records each
Model Schema of Customers, Orders and Modified Nodes ✅ PASS Zero schema changes - all 8 columns in customers retain original data types and structure
Value Diff of Customers ✅ PASS 100% row match (1,856/1,856) on customer IDs and customer lifetime values - perfect data consistency

🔍 Suggested Actions

  • Verify downstream calculations: Run query_diff on customer_order_pattern and customer_segments to confirm aggregations correctly reference the refactored customers model structure
  • Validate intermediate model logic: Execute profile_diff on int_customer_orders and int_customer_payments to ensure payment and order distributions match expectations from source data
  • Monitor compilation warnings: Address the dbt macro rendering warning for new intermediate models despite successful table creation - verify model YAML definitions are complete
  • Spot-check downstream impacts: Compare a sample of 10-20 rows from customer_order_pattern before/after to manually confirm aggregation accuracy post-refactor
  • Review CTE extraction rationale: Confirm that extracting CTEs into int_customer_orders and int_customer_payments aligns with project modeling standards and naming conventions
    Please use the link below to launch your Recce Cloud session.

Launch Recce Cloud Session


Was this summary helpful? 👍 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants