
Loading...
Staging chonks are the first transformation layer. They clean, rename, and cast your source data into a consistent format that's easy to work with downstream.
Staging models create a 1:1 mapping with your source tables, applying consistent transformations and naming conventions.
The staging model SQL with CTEs for source and renaming
Schema file with tests and documentation
DataChonk follows these staging conventions to ensure consistency across your project.
One staging model per source table. No more, no less.
Use snake_case, remove vendor prefixes, add semantic meaning.
Explicit type casting for consistency across warehouses.
Keep staging models simple—joins happen downstream.
Save that for intermediate and mart layers.
Here's what a staging model looks like when generated by DataChonk.
with source as (
select * from {{ source('raw_ecommerce', 'orders') }}
),
renamed as (
select
-- ids
order_id,
customer_id,
-- strings
lower(status) as order_status,
-- numerics
cast(total_amount as decimal(18,2)) as order_total,
cast(discount_amount as decimal(18,2)) as discount_amount,
-- dates
cast(order_date as date) as order_date,
cast(shipped_date as date) as shipped_date,
-- timestamps
cast(created_at as timestamp) as created_at,
cast(updated_at as timestamp) as updated_at
from source
)
select * from renamedCommon transformations applied by staging chonks.
| Property | Type | Default | Description |
|---|---|---|---|
| Remove prefixes | - | - | cust_name → customer_name |
| Snake case | - | - | firstName → first_name |
| Lowercase strings | - | - | ACTIVE → active |
| Type casting | - | - | string → decimal(18,2) |
| Null handling | - | - | coalesce(amount, 0) |
Warehouse-Specific
Pro Tip
_loaded_at or_synced_at column if your source has one—it's useful for incremental models downstream.| Property | Type | Default | Description |
|---|---|---|---|
| naming_convention | string | stg_{source}__{table} | Model file naming pattern |
| cast_types | boolean | true | Automatically cast columns to appropriate types |
| lowercase_strings | boolean | true | Convert string columns to lowercase |
| remove_prefixes | array | [] | Prefixes to strip from column names |
| include_metadata | boolean | true | Include _loaded_at type columns |