Skip to content

Analytic windows: over, Window and then (HQL-0050) - #11

Merged
ewiger merged 5 commits into
mainfrom
feat/analytic-windows
Nov 12, 2026
Merged

ewiger merged 5 commits into
mainfrom
feat/analytic-windows

Conversation

@ewiger

@ewiger ewiger commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What

The analytic windows of HQL-0050, and a total order for keyed selection. over partitions a sequence by a key, orders each partition, and gives one value per row, at the row's input position, from the row and its Window:

ledger
| over(by = t => t.account, order = t => t.seq,
       into = (t, w) => w | running | map(x => x.amount) | sum)
  • over(by, order, into) in seq: order is a key or a comparison; rows equal under it keep their input order. No row is merged or dropped.
  • Window<T> in core: row_number, rank, dense_rank, lag, lead, first, last, size, and the frames running, rows(before, after) and whole. Called as a step, w | row_number, or as a receiver, w.row_number().
  • then in collections: compare(a.at, b.at) | then(compare(a.seq, b.seq)), the second comparison evaluated only on a tie. A comparison that ends in a unique key is a total order, so keyed selection does not depend on input order.
  • Refused at check time: an into whose result holds a Window, and over of a Stream or a Set.
  • sort is specified as stable, which it already was.

Breaking

Window is a standard type name, so a program's own type Window is refused, as Group and Pair already are. The structural examples and the type-contracts page call their contract Interval now.

Not in this PR

HQL-0050 is implemented in part. Carrying input position across splits, and keyed selection as a partial reduction, wait for a backend that splits; localhost does not.

Docs

A new book page, Part II's "Windows" under OLAP, a tie-rule paragraph on the Deduplication page, generated reference pages, the changelog, and HQL-0050's spec as built.

Testing

examples/windows/ holds nine cases and two refusals, and examples/pipelines/queries/ranked-deduplication.hql runs the shop's replay through over. The cases were written as proposed with hand-computed results before the implementation, then promoted. cargo test --locked (653), cargo clippy --locked --all-targets, cargo fmt --check and hql reference --check pass locally; mkdocs build --strict was not run locally (no mike plugin here).

@ewiger
ewiger merged commit b6fa4ce into main Nov 12, 2026
5 checks passed
@ewiger
ewiger deleted the feat/analytic-windows branch November 12, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant