
Loading...
Entity chonks create dimension tables that represent business entities like customers, products, or locations. They bring together attributes from multiple sources into a single, analysis-ready table.
Entity chonks produce dimension models with aggregated metrics, business classifications, and optional slowly-changing dimension (SCD) support.
The dimension model SQL with joins and aggregations
Optional hashed keys for multi-column joins
Lifetime metrics baked into the dimension
Simple dimensions that don't track history. Current state only. Great for attributes that don't change or where history isn't important.
Slowly changing dimensions that track changes over time with valid_from/valid_to dates. Essential for accurate historical analysis.
Here's a customer dimension with lifetime metrics and business segmentation.
with customers as (
select * from {{ ref('stg_ecommerce__customers') }}
),
orders as (
select * from {{ ref('stg_ecommerce__orders') }}
),
customer_orders as (
select
customer_id,
min(order_date) as first_order_date,
max(order_date) as most_recent_order_date,
count(*) as number_of_orders,
sum(order_total) as lifetime_value
from orders
group by 1
),
final as (
select
customers.customer_id,
customers.first_name,
customers.last_name,
customers.email,
customers.created_at as customer_created_at,
-- order metrics
coalesce(customer_orders.first_order_date, null) as first_order_date,
coalesce(customer_orders.most_recent_order_date, null) as most_recent_order_date,
coalesce(customer_orders.number_of_orders, 0) as number_of_orders,
coalesce(customer_orders.lifetime_value, 0) as lifetime_value,
-- derived segmentation
case
when customer_orders.number_of_orders >= 10 then 'vip'
when customer_orders.number_of_orders >= 3 then 'regular'
when customer_orders.number_of_orders >= 1 then 'new'
else 'prospect'
end as customer_segment
from customers
left join customer_orders using (customer_id)
)
select * from finalPerformance Tip
| Property | Type | Default | Description |
|---|---|---|---|
| scd_type | 1 | 2 | 1 | Slowly Changing Dimension type |
| include_surrogate_key | boolean | false | Generate hashed surrogate key |
| aggregate_metrics | boolean | true | Include pre-calculated lifetime metrics |
| business_segments | boolean | true | Generate business classification columns |
| valid_from_column | string | valid_from | SCD Type 2 start date column |
| valid_to_column | string | valid_to | SCD Type 2 end date column |