Fact-Dimension Pattern
Core pattern for modeling fact and dimension tables.
Overview
The fact-dimension pattern is the foundation of dimensional modeling. Facts are events/transactions, dimensions are descriptive attributes.
Fact Tables
Facts represent business events or transactions.
Characteristics:
- Higher cost (100)
- Many rows
- Contain measures (aggregatable metrics)
- Foreign keys to dimensions
Example:
name: Orders
cost: 100
fields:
- type: measure
name: Total Revenue
expression:
sql: sum(amount)
Dimension Tables
Dimensions provide context for facts.
Characteristics:
- Lower cost (10)
- Fewer rows
- Contain dimensions (categorical fields)
- Primary keys
Example:
name: Customer
cost: 10
fields:
- type: dimension
name: Customer ID
expression:
primary_key: true
sql: customer_id
Relationships
Facts join to dimensions:
orders_customer:
left: Orders
right: Customer
sql: left.customer_id = right.id
cardinality: many_to_one
Best Practices
- Fact cost: 100 - Higher cost
- Dimension cost: 10 - Lower cost
- Many-to-one - Fact to dimension
- Primary keys - On dimensions
- Measures in facts - Aggregatable metrics