Five commerce questions with one LOD model¶
Run the example¶
Install Dosi and the DuckDB CLI. Use the model and seed shipped in the release; no Python or regression script is required.
export DOSI_EXAMPLES=~/.local/share/dosi/examples
cp -R "$DOSI_EXAMPLES/lod-commerce" ./lod-commerce
cd lod-commerce
duckdb lod_commerce.duckdb < seed.sql
dosi validate --model model.yaml --strict
Use a new database file. For manual archives, first point DOSI_EXAMPLES at that archive. The seed comes from testkit data; queries.json, expected.json, independent SQL and verification scripts are not shipped.
Data and business definitions¶
The current seed contains 10 customers, 41 orders and 9 refund applications. Model dataset users maps to physical table customers; paid_total includes amounts only for completed orders. Data includes nulls, unmatched relationships and non-completed orders, rather than the older 2030 demonstration dataset. The queries use 2026 intervals, inclusive at the start and exclusive at the end.
How the model separates calculation grains¶
Read the bundled model.yaml instead of copying a second potentially stale definition. Fixed fields calculate by customer; include aggregates at a finer grain first; exclude removes a grouping field; independent parameters control separate time windows. The forms are exercised in separate queries below.
1. How much do repeat buyers contribute?¶
dosi query --model model.yaml \
--metrics buyers,paid_total \
--group-by orders.buyer_group \
--context-filter "orders.paid_date < DATE '2026-06-01'" \
--order buyer_group \
--execute --db lod_commerce.duckdb --format json
| buyer_group | buyers | paid_total |
|---|---|---|
| once | 1 | 47.49 |
| repeat | 6 | 19873.0 |
2. Which acquisition channels bring higher-spending buyers?¶
dosi query --model model.yaml \
--metrics mean_lifetime_paid \
--group-by users.acquisition_channel \
--context-filter "orders.paid_date < DATE '2026-06-01'" \
--order acquisition_channel \
--execute --db lod_commerce.duckdb --format json
| acquisition_channel | mean_lifetime_paid |
|---|---|
| ads | 2191.5 |
| organic | 3102.398 |
| NULL | 25.5 |
3. How often do buyers purchase within a channel?¶
dosi query --model model.yaml \
--metrics mean_orders,max_orders \
--group-by orders.channel \
--start-time 2026-04-01 \
--end-time 2026-05-01 \
--time-dimension orders.paid_date \
--execute --db lod_commerce.duckdb --format json
| channel | mean_orders | max_orders |
|---|---|---|
| app | 1.0 | 1 |
4. What does the daily app sales report show?¶
dosi query --model model.yaml \
--metrics paid_total,site_amount,daily_site_share,app_month_amount,app_month_share \
--group-by orders.channel,orders.paid_date \
--where "orders.channel = 'app'" \
--start-time 2026-04-01 \
--end-time 2026-05-01 \
--time-dimension orders.paid_date \
--order paid_date \
--execute --db lod_commerce.duckdb --format json
| channel | paid_date | paid_total | site_amount | daily_site_share | app_month_amount | app_month_share |
|---|---|---|---|---|---|---|
| app | 2026-04-05 | 842.0 | 842.0 | 1.0 | 1707.0 | 0.4932630345635618 |
| app | 2026-04-15 | 865.0 | 865.0 | 1.0 | 1707.0 | 0.5067369654364382 |
--where selects displayed app rows; it is not a substitute for a context filter that changes every LOD denominator. Both dates have app-month amount 1707.
5. Who bought in April but did not return in May?¶
dosi select --model model.yaml \
--from users \
--fields users.user_id,users.region,users.reference_paid,users.observation_orders,users.window_refunded \
--where "users.reference_orders > 0 AND users.observation_orders = 0" \
--param reference_start=20260401 \
--param reference_end=20260501 \
--param observation_start=20260501 \
--param observation_end=20260601 \
--param refund_start=20260401 \
--param refund_end=20260501 \
--param refund_status=SUCCEEDED \
--limit 10000 \
--execute --db lod_commerce.duckdb --format json
| user_id | region | reference_paid | observation_orders | window_refunded |
|---|---|---|---|---|
| 1 | east | 842.0 | 0 | 50.0 |
| 3 | east | 865.0 | 0 | 0.0 |
The three parameter windows are independent. Do not add a global time range that truncates the other windows. NULL values remain NULL.
What this example proves¶
These commands were executed using the exported seed and model. Full regression cases and expected answers remain in testkit and are not installation prerequisites. See LOD and detail queries for combination limits.