Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/concepts/formulas.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Field formulas define what data columns a query returns. They go in the `fields`

```json
"fields": [
{"formula": "count"},
"count",
{"formula": "revenue / count", "name": "aov", "label": "Average Order Value"},
{"formula": "cumsum(revenue)"},
"cumsum(revenue)",
...
]
```
Expand Down Expand Up @@ -69,7 +69,7 @@ Field formulas support arbitrary nesting — functions can wrap other functions
```json
"fields": [
{"formula": "change(cumsum(revenue))", "name": "cumsum_delta"},
{"formula": "last(change(cumsum(revenue)))"},
"last(change(cumsum(revenue)))",
{"formula": "cumsum(revenue / count)", "name": "running_aov"},
{"formula": "cumsum(revenue) / count", "name": "cumsum_div_count"},
...
Expand All @@ -89,12 +89,12 @@ The ranking granularity depends on the query's dimensions and time dimensions. E
```json
{
"source_model": "orders",
"dimensions": [{"name": "customer_name"}],
"dimensions": ["customer_name"],
"fields": [
{"formula": "revenue_sum"},
"revenue_sum",
{"formula": "rank(revenue_sum)", "name": "rnk"}
],
"order": [{"column": {"name": "revenue_sum"}, "direction": "desc"}]
"order": [{"column": "revenue_sum", "direction": "desc"}]
}
```

Expand All @@ -119,10 +119,10 @@ Ties receive the same rank (standard SQL `RANK` behavior): if two rows tie at ra
{
"source_model": "orders",
"fields": [
{"formula": "revenue_sum"},
"revenue_sum",
{"formula": "last(revenue_sum)", "name": "latest_revenue"}
],
"time_dimensions": [{"dimension": {"name": "created_at"}, "granularity": "month"}]
"time_dimensions": [{"dimension": "created_at", "granularity": "month"}]
}
```

Expand Down
14 changes: 7 additions & 7 deletions docs/concepts/ingestion.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ After ingestion, you can query rolled-up dimensions directly:
```json
{
"source_model": "orders",
"fields": [{"formula": "count"}, {"formula": "amount_sum"}],
"dimensions": [{"name": "customers.name"}]
"fields": ["count", "amount_sum"],
"dimensions": ["customers.name"]
}
```

Expand All @@ -95,8 +95,8 @@ Or transitively joined dimensions (using full path):
```json
{
"source_model": "orders",
"fields": [{"formula": "count"}],
"dimensions": [{"name": "customers.regions.name"}]
"fields": ["count"],
"dimensions": ["customers.regions.name"]
}
```

Expand All @@ -113,10 +113,10 @@ This avoids table alias collisions and allows querying both paths simultaneously
{
"source_model": "orders",
"dimensions": [
{"name": "customers.regions.name"},
{"name": "warehouses.regions.name"}
"customers.regions.name",
"warehouses.regions.name"
],
"fields": [{"formula": "count"}]
"fields": ["count"]
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ engine.create_model_from_query(
query=SlayerQuery(
source_model="orders",
time_dimensions=[...],
fields=[{"formula": "count"}, {"formula": "total_amount"}],
fields=["count", "total_amount"],
),
name="monthly_summary",
)
Expand Down
56 changes: 28 additions & 28 deletions docs/concepts/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A time dimension with a required granularity and an optional date range. Support

```json
{
"dimension": {"name": "created_at"},
"dimension": "created_at",
"granularity": "month",
"date_range": ["2024-01-01", "2024-12-31"],
"label": "Order Month"
Expand All @@ -58,7 +58,7 @@ A time dimension with a required granularity and an optional date range. Support
## OrderItem

```json
{"column": {"name": "count"}, "direction": "desc"}
{"column": "count", "direction": "desc"}
```

Via MCP: `{"column": "count", "direction": "desc"}`
Expand Down Expand Up @@ -133,7 +133,7 @@ Filters can reference names of computed fields — transforms and arithmetic exp
```json
{
"fields": [
{"formula": "revenue"},
"revenue",
{"formula": "change(revenue)", "name": "rev_change"}
],
"filters": ["rev_change < 0"]
Expand Down Expand Up @@ -165,8 +165,8 @@ Post-filters can be combined with regular filters — base filters (on dimension
```json
{
"source_model": "orders",
"fields": [{"formula": "count"}],
"dimensions": [{"name": "status"}]
"fields": ["count"],
"dimensions": ["status"]
}
```

Expand All @@ -175,9 +175,9 @@ Post-filters can be combined with regular filters — base filters (on dimension
```json
{
"source_model": "orders",
"fields": [{"formula": "revenue_sum"}],
"fields": ["revenue_sum"],
"time_dimensions": [{
"dimension": {"name": "created_at"},
"dimension": "created_at",
"granularity": "month",
"date_range": ["2024-01-01", "2024-12-31"]
}]
Expand All @@ -189,9 +189,9 @@ Post-filters can be combined with regular filters — base filters (on dimension
```json
{
"source_model": "orders",
"fields": [{"formula": "revenue_sum"}],
"dimensions": [{"name": "customer_name"}],
"order": [{"column": {"name": "revenue_sum"}, "direction": "desc"}],
"fields": ["revenue_sum"],
"dimensions": ["customer_name"],
"order": [{"column": "revenue_sum", "direction": "desc"}],
"limit": 5
}
```
Expand All @@ -201,7 +201,7 @@ Post-filters can be combined with regular filters — base filters (on dimension
```json
{
"source_model": "orders",
"fields": [{"formula": "count"}],
"fields": ["count"],
"filters": ["status = 'completed' or status = 'pending'"]
}
```
Expand All @@ -212,13 +212,13 @@ Post-filters can be combined with regular filters — base filters (on dimension
{
"source_model": "orders",
"fields": [
{"formula": "count"},
{"formula": "revenue_sum"},
"count",
"revenue_sum",
{"formula": "revenue_sum / count", "name": "aov", "label": "Average Order Value"},
{"formula": "cumsum(revenue_sum)", "name": "running"},
{"formula": "change(revenue_sum)", "name": "mom_change"}
],
"time_dimensions": [{"dimension": {"name": "created_at"}, "granularity": "month"}]
"time_dimensions": [{"dimension": "created_at", "granularity": "month"}]
}
```

Expand All @@ -230,10 +230,10 @@ When models have [joins](models.md#joins), you can reference measures from joine
{
"source_model": "orders",
"fields": [
{"formula": "count"},
{"formula": "customers.avg_score"}
"count",
"customers.avg_score"
],
"time_dimensions": [{"dimension": {"name": "created_at"}, "granularity": "month"}]
"time_dimensions": [{"dimension": "created_at", "granularity": "month"}]
}
```

Expand All @@ -248,12 +248,12 @@ Pass a list of queries to `execute()`. Earlier queries are named sub-queries, th
{
"name": "monthly",
"source_model": "orders",
"fields": [{"formula": "count"}, {"formula": "total_amount"}],
"time_dimensions": [{"dimension": {"name": "created_at"}, "granularity": "month"}]
"fields": ["count", "total_amount"],
"time_dimensions": [{"dimension": "created_at", "granularity": "month"}]
},
{
"source_model": "monthly",
"fields": [{"formula": "count"}]
"fields": ["count"]
}
]
```
Expand All @@ -267,13 +267,13 @@ You can also join named queries to models:
{
"name": "customer_scores",
"source_model": "customers",
"dimensions": [{"name": "id"}],
"fields": [{"formula": "avg_score"}]
"dimensions": ["id"],
"fields": ["avg_score"]
},
{
"source_model": {"source_name": "orders", "joins": [{"target_model": "customer_scores", "join_pairs": [["customer_id", "id"]]}]},
"fields": [{"formula": "count"}, {"formula": "customer_scores.avg_score_avg"}],
"time_dimensions": [{"dimension": {"name": "created_at"}, "granularity": "month"}]
"fields": ["count", "customer_scores.avg_score_avg"],
"time_dimensions": [{"dimension": "created_at", "granularity": "month"}]
}
]
```
Expand All @@ -291,8 +291,8 @@ Extend a model inline with extra dimensions, measures, or joins — without modi
"dimensions": [{"name": "tier", "sql": "CASE WHEN amount > 100 THEN 'high' ELSE 'low' END"}],
"joins": [{"target_model": "customer_scores", "join_pairs": [["customer_id", "id"]]}]
},
"dimensions": [{"name": "tier"}],
"fields": [{"formula": "count"}]
"dimensions": ["tier"],
"fields": ["count"]
}
```

Expand All @@ -305,8 +305,8 @@ Dimensions from transitively joined models can be referenced with dotted paths.
```json
{
"source_model": "orders",
"dimensions": [{"name": "customers.regions.name"}],
"fields": [{"formula": "count"}]
"dimensions": ["customers.regions.name"],
"fields": ["count"]
}
```

Expand Down
Loading
Loading