mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 22:26:53 +00:00
A broad documentation pass across the areas LanceDB Enterprise and Embedded diverge on most: **Data Curation** -- GPU Function execution, Slurm scheduling (and what Slurm is, for readers new to it), blob late materialization as its own page, joins, aggregation/profiling, sampling, near-duplicate detection, chunking, distributed shuffle, and IVF-partition clustering. **Feature Engineering** -- computed columns and materialized views, restructured to lead with the Function-based path and show the SQL form side by side with Python throughout; a single Auto Refresh page instead of duplicating scheduling details on every refresh page; adaptive execution; checkpointing; GPU and Slurm placement for refresh workers; a Training Cache page for the PyTorch data loader's automatic cache benefit. **Security & Governance** -- an Audit Log reference (schema, access, grants), Secrets promoted to an ordinary catalog object with their own SQL DDL and a vending/rotation guide, and privilege-table fixes verified against the authorization source. **Deployment & Maintenance** -- Horizontal Scaling and OpenTelemetry moved into a real Deployment area; Automated Cleanup folded into Intelligent Auto-Maintenance (every other maintenance decision already lived there); RTE Compaction and Advanced Conflict Resolution documented in depth. **Landing page** -- the Enterprise feature comparison table reorganized (several redundant or stale rows removed, several new areas added), and the "why Enterprise" bullets replaced with ones tied to a concrete page (Performance, Scale, Fault tolerance, Multicloud deployment, Simplify operations) instead of vague promises. Plus a full pass addressing lancedb-gatekeeper's review: a real test-safety bug (a quickstart test could silently overwrite and delete a deployment's own `frames` table), a fabricated SQL statement with no backing implementation, an actual dedup-guarantee bug in `take_row_ids`, and dozens of documentation-accuracy fixes verified against source rather than taken on faith -- each either fixed, or left with an explicit note on why it needs a feature or deployment owner's sign-off instead of being guessed at. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018PXMCbRH6i5w47TsjeEUMT --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
112 lines
2.9 KiB
Plaintext
112 lines
2.9 KiB
Plaintext
---
|
|
title: "Window functions"
|
|
sidebarTitle: "Window Functions"
|
|
description: "Compute over a set of rows related to the current one, without collapsing them."
|
|
icon: chart-simple
|
|
keywords: ["window", "over", "partition by", "row_number", "rank", "lag", "lead"]
|
|
availability:
|
|
embedded: unavailable
|
|
enterprise: available
|
|
---
|
|
|
|
A window function computes across a set of rows related to the current one and
|
|
returns a value **per row**. That is the difference from
|
|
[aggregation](/sql/dql/aggregation), which collapses the rows it covers.
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
SELECT
|
|
title,
|
|
score,
|
|
row_number() OVER (PARTITION BY category ORDER BY score DESC) AS rank
|
|
FROM documents
|
|
```
|
|
</CodeGroup>
|
|
|
|
Every row survives; each one gains its rank within its category.
|
|
|
|
## The window {#window}
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
OVER (
|
|
[PARTITION BY expr [, ...]]
|
|
[ORDER BY expr [, ...]]
|
|
[ROWS | RANGE BETWEEN frame_start AND frame_end]
|
|
)
|
|
```
|
|
</CodeGroup>
|
|
|
|
`PARTITION BY` splits the rows into independent groups. `ORDER BY` orders them
|
|
inside each partition. Supply an ordering for useful ranks, and a stable
|
|
tie-breaker when selecting one row from several equal values. The frame clause narrows the window further, which is
|
|
how running totals and moving averages are expressed:
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
SELECT
|
|
created_at,
|
|
sum(amount) OVER (ORDER BY created_at ROWS UNBOUNDED PRECEDING) AS running_total,
|
|
avg(amount) OVER (ORDER BY created_at ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS trailing_7
|
|
FROM transactions
|
|
```
|
|
</CodeGroup>
|
|
|
|
A `WINDOW` clause names a definition when several functions share one:
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
SELECT
|
|
row_number() OVER w,
|
|
lag(score) OVER w
|
|
FROM documents
|
|
WINDOW w AS (PARTITION BY category ORDER BY score DESC)
|
|
```
|
|
</CodeGroup>
|
|
|
|
## The functions {#functions}
|
|
|
|
Registered in DataFusion 54.
|
|
|
|
**Ranking**
|
|
|
|
```text
|
|
row_number rank dense_rank percent_rank cume_dist ntile
|
|
```
|
|
|
|
**Offset and positional**
|
|
|
|
```text
|
|
lag lead first_value last_value nth_value
|
|
```
|
|
|
|
**Aggregates**
|
|
|
|
Any [aggregate function](/sql/dql/aggregation#functions) used with `OVER` becomes a
|
|
window function. This is how running totals and moving averages are written.
|
|
|
|
## Deduplicating with a window {#dedup}
|
|
|
|
The common practical use: keep one row per key, chosen by some ordering. A
|
|
window ranks, and an outer query filters:
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
WITH ranked AS (
|
|
SELECT *, row_number() OVER (PARTITION BY doc_id ORDER BY version DESC) AS rn
|
|
FROM revisions
|
|
)
|
|
SELECT * FROM ranked WHERE rn = 1
|
|
```
|
|
</CodeGroup>
|
|
|
|
The outer query is needed because a window function cannot appear in `WHERE`:
|
|
windows are computed after filtering, so the predicate would have nothing to
|
|
read.
|
|
|
|
<Note>
|
|
Window functions sort within each partition, so on a large table they are among
|
|
the more expensive things you can ask for. Filter first, and check the cost with
|
|
[Explain Analyze](/basics/sql#analyze-a-query-plan).
|
|
</Note>
|