xiaohongshu
xiaohongshu
Comprehensive guide to ELT (Extract, Load, Transform) modeling patterns, dimensional modeling, fact and dimension tables, and data warehouse design
Full skill instructions
Extract → Transform → Load
1. Extract from source
2. Transform in ETL tool (Informatica, Talend)
3. Load to warehouse
Pros: Clean data before loading
Cons: Slow, expensive transformation servers
Extract → Load → Transform
1. Extract from source
2. Load raw data to warehouse
3. Transform in warehouse (SQL, dbt)
Pros: Fast loading, leverage warehouse power
Cons: Raw data in warehouse (need governance)
dim_customers
|
dim_products
|
fct_orders ← Central fact table
|
dim_dates
|
dim_locations
Characteristics:
dim_customers
|
dim_customer_segments
|
fct_orders
|
dim_products
|
dim_product_categories
Characteristics:
Recommendation: Use star schema for analytics (faster)
Fact table: Stores measurable events (transactions, orders, clicks)
Transaction Facts:
-- One row per transaction
fct_orders:
order_id (PK)
customer_id (FK)
product_id (FK)
order_date_id (FK)
quantity
amount
Periodic Snapshot Facts:
-- One row per period (daily, monthly)
fct_inventory_daily:
date_id (PK)
product_id (PK)
warehouse_id (PK)
quantity_on_hand
quantity_sold
Accumulating Snapshot Facts:
-- One row per process (order lifecycle)
fct_order_lifecycle:
order_id (PK)
order_date
payment_date
shipment_date
delivery_date
days_to_ship
days_to_deliver
CREATE TABLE fct_orders (
-- Surrogate key
order_key BIGINT PRIMARY KEY,
-- Natural key
order_id VARCHAR(50) NOT NULL,
-- Foreign keys (dimensions)
customer_key BIGINT NOT NULL,
product_key BIGINT NOT NULL,
date_key INT NOT NULL,
-- Degenerate dimensions (no separate dim table)
order_number VARCHAR(50),
-- Measures
quantity INT,
unit_price DECIMAL(10,2),
total_amount DECIMAL(10,2),
discount_amount DECIMAL(10,2),
-- Audit columns
created_at TIMESTAMP,
updated_at TIMESTAMP
);
Dimension table: Stores descriptive attributes (who, what, where, when)
CREATE TABLE dim_customers (
-- Surrogate key
customer_key BIGINT PRIMARY KEY,
-- Natural key
customer_id VARCHAR(50) NOT NULL,
-- Attributes
customer_name VARCHAR(255),
email VARCHAR(255),
phone VARCHAR(50),
-- Hierarchies
city VARCHAR(100),
state VARCHAR(100),
country VARCHAR(100),
region VARCHAR(100),
-- Segments
customer_segment VARCHAR(50),
customer_tier VARCHAR(50),
-- SCD Type 2 columns
effective_date DATE,
expiration_date DATE,
is_current BOOLEAN,
-- Audit columns
created_at TIMESTAMP,
updated_at TIMESTAMP
);
Type 1: Overwrite
-- Customer moves, update address
UPDATE dim_customers
SET city = 'New York', state = 'NY'
WHERE customer_id = '123';
-- No history preserved
Type 2: Add New Row (Historical)
-- Customer moves, add new row
INSERT INTO dim_customers (
customer_id, city, state,
effective_date, is_current
) VALUES (
'123', 'New York', 'NY',
'2024-01-15', TRUE
);
-- Mark old row as not current
UPDATE dim_customers
SET is_current = FALSE,
expiration_date = '2024-01-14'
WHERE customer_id = '123'
AND is_current = TRUE;
-- History preserved
Type 3: Add New Column
-- Track previous value
ALTER TABLE dim_customers
ADD COLUMN previous_city VARCHAR(100);
UPDATE dim_customers
SET previous_city = city,
city = 'New York'
WHERE customer_id = '123';
Grain: Level of detail in fact table (one row represents what?)
Order grain: One row per order
Order line grain: One row per product in order
Daily grain: One row per day per product
Hourly grain: One row per hour per product
Too fine (order line):
- More rows
- More storage
- More flexibility
Too coarse (monthly):
- Fewer rows
- Less storage
- Less flexibility
Balance: Choose finest grain needed for analysis
Data Marts (Star Schemas) → Enterprise Data Warehouse
Pros:
- Fast to implement
- Business-friendly (denormalized)
- Query performance
Cons:
- Data redundancy
- Hard to change
Enterprise Data Warehouse (3NF) → Data Marts
Pros:
- Single source of truth
- Flexible
- Less redundancy
Cons:
- Slow to implement
- Complex queries (many joins)
Modern Approach: Hybrid (normalized staging, dimensional marts)
Hubs: Business keys (customers, products)
Links: Relationships (orders link customers + products)
Satellites: Descriptive attributes (customer details)
-- Hub: Customer
CREATE TABLE hub_customer (
customer_hub_key BIGINT PRIMARY KEY,
customer_id VARCHAR(50) UNIQUE,
load_date TIMESTAMP,
record_source VARCHAR(50)
);
-- Satellite: Customer Details
CREATE TABLE sat_customer_details (
customer_hub_key BIGINT,
load_date TIMESTAMP,
customer_name VARCHAR(255),
email VARCHAR(255),
phone VARCHAR(50),
PRIMARY KEY (customer_hub_key, load_date)
);
-- Link: Order
CREATE TABLE link_order (
order_link_key BIGINT PRIMARY KEY,
customer_hub_key BIGINT,
product_hub_key BIGINT,
load_date TIMESTAMP
);
Pros:
Cons:
Conformed dimension: Shared across multiple fact tables
-- dim_date used by multiple facts
dim_date ← fct_orders
← fct_shipments
← fct_returns
-- Ensures consistent date attributes
-- Customer can have multiple accounts
-- Account can have multiple customers
CREATE TABLE bridge_customer_account (
customer_key BIGINT,
account_key BIGINT,
allocation_percentage DECIMAL(5,2),
PRIMARY KEY (customer_key, account_key)
);
Junk dimension: Collection of low-cardinality flags
-- Instead of many boolean columns in fact
CREATE TABLE dim_order_flags (
order_flag_key INT PRIMARY KEY,
is_gift BOOLEAN,
is_express_shipping BOOLEAN,
is_first_order BOOLEAN,
has_discount BOOLEAN
);
-- Fact table references junk dimension
fct_orders:
order_key
customer_key
order_flag_key ← Reference to junk dimension
amount
Role-playing dimension: Same dimension used multiple times with different meanings
-- dim_date used multiple times
fct_orders:
order_key
order_date_key ← dim_date (order date)
ship_date_key ← dim_date (ship date)
delivery_date_key ← dim_date (delivery date)
amount
-- Natural key: Business identifier
customer_id = 'CUST-12345'
-- Surrogate key: System-generated
customer_key = 1001 (auto-increment or hash)
-- Auto-increment
customer_key BIGINT AUTO_INCREMENT PRIMARY KEY
-- Hash (dbt)
{{ dbt_utils.surrogate_key(['customer_id', 'effective_date']) }}
-- Sequence (PostgreSQL)
customer_key BIGINT DEFAULT nextval('customer_key_seq')
Purpose: Exact copy of source data
Format: As-is from source
Schema: Source schema
Example: raw_salesforce_accounts
Purpose: Cleaned, standardized
Format: Consistent types, naming
Schema: Staging schema
Example: stg_salesforce_accounts
Purpose: Business-ready
Format: Dimensional models
Schema: Analytics schema
Example: dim_customers, fct_orders
✓ "One row per order"
✗ "Order data"
✓ customer_key BIGINT
✗ customer_id VARCHAR(50)
✓ dim_customers includes city, state, country
✗ Separate dim_cities, dim_states, dim_countries
✓ fct_orders: Keys + measures only
✗ fct_orders: Keys + measures + customer name, product name
✓ dim_date shared across all facts
✗ Each fact has own date dimension
-- Capture state once per day
INSERT INTO fct_inventory_daily
SELECT
CURRENT_DATE as snapshot_date,
product_id,
warehouse_id,
quantity_on_hand,
quantity_reserved
FROM current_inventory;
-- Running totals
SELECT
order_date,
SUM(amount) OVER (
ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) as cumulative_revenue
FROM fct_orders;
ELT: Extract → Load → Transform (modern approach)
Dimensional Modeling:
Fact Types:
SCD Types:
Grain: Level of detail (define clearly!)
Surrogate Keys: Use for performance and SCD
Layers:
Best Practices:
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience