Skip to content

Commit 9e1f04a

Browse files
committed
Clarify window function handling in coverage analyzer docs
Made it clear that: - Base aggregations ARE extracted (both standalone and inside window functions) - Dimensions from GROUP BY and PARTITION BY ARE extracted - Window calculations themselves are NOT extracted (the OVER() parts) - Window-only functions (ROW_NUMBER, etc.) are NOT extracted Previous wording said window functions were 'intentionally ignored' which was misleading - we DO extract the base aggregations, just not the window calculations on top of them.
1 parent b9d143d commit 9e1f04a

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

docs/coverage-analyzer.qmd

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,9 @@ GROUP BY o1.status
315315
```
316316
**Extracts**: Single `orders` model with appropriate dimensions
317317

318-
## Patterns NOT Extracted
318+
## Window Functions
319319

320-
### Window Functions
321-
322-
Window functions are post-aggregation operations and are **intentionally ignored**:
320+
Window functions have special handling:
323321

324322
```sql
325323
SELECT
@@ -331,13 +329,26 @@ FROM orders
331329
GROUP BY status
332330
```
333331

334-
**Extracts**:
335-
- Base metric: `order_count` (COUNT(*))
336-
- Ignores: `pct_of_total`, `rank` (window functions)
332+
**What Gets Extracted**:
333+
- ✅ Base aggregations: `COUNT(*)` from `order_count`
334+
- ✅ Base aggregations inside window functions: `COUNT(*)` from `SUM(COUNT(*)) OVER()`
335+
- ✅ Dimensions from GROUP BY and PARTITION BY: `status`
336+
337+
**What Gets Ignored**:
338+
- ❌ Window calculations: `pct_of_total` (the division and `OVER()` part)
339+
- ❌ Window-only functions: `rank` (`ROW_NUMBER()` has no base aggregation)
340+
341+
**Why**: Window functions apply transformations *after* aggregation. The analyzer extracts the base data you need (aggregations, dimensions), but the window calculations themselves aren't extracted.
342+
343+
**If you want** `pct_of_total` as a reusable metric, manually add to generated model:
344+
```yaml
345+
metrics:
346+
- name: pct_of_total
347+
type: derived
348+
sql: "order_count * 100.0 / SUM(order_count) OVER()"
349+
```
337350
338-
**Why**: Window functions are transformations applied after aggregation. Model them as:
339-
- **Derived metrics** if reusable: `pct_of_total`
340-
- **Table calculations** if one-off: `rank`
351+
Or apply as a post-query table calculation for one-off use.
341352
342353
### CTEs (WITH Clauses)
343354

0 commit comments

Comments
 (0)