Something went wrong. Try again.
SQL frontend over the catalog engine
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
(** Window functions.
A window function is computed over the rows of the partition of the current row, in order, within a frame (windowfunctions.html section 1). [Window] computes it in OCaml over the rows a scan produced. A first {!Ir} run computes the expressions a window reads (its arguments, [PARTITION BY] and [ORDER BY] keys and frame offsets) over those rows. A second run computes the select list with each window replaced by its value, and applies [ORDER BY], [DISTINCT] and [LIMIT]. *)
val scan_select : Lower.layout -> Ast.select -> Ast.select * Lower.layout(** [scan_select layout s] is the select whose rows {!scan} reads for the window select [s] over the sources [layout] names, with the segments that name those rows. It reads [s]'s sources, joins and [WHERE] and projects every column [*] does, then the hidden rowid of each source that has one, so a window, a [PARTITION BY] or an [ORDER BY] may read [rowid], [oid] or [_rowid_] as the scan does. A [*] in [s] still expands to the declared columns alone. *)
val scan : params:Ast.value array -> ?affinity:(int * int -> Value_ops.affinity option) -> ?membership:(Ast.select -> Query.membership) -> ?grouped:bool -> encoding:Encoding.t -> Lower.layout -> Ast.select -> Ast.value list list -> Ast.value list list(** [scan ~params ~affinity ~membership ~grouped ~encoding segments s rows] is the output of [s] from the [rows] its scan produced. [segments] names the sources of those rows in scan order, as [(alias, columns)], and each row is the concatenation of their columns. [affinity] and [membership] are as in {!Lower.query}, keyed on [segments]; without them, a comparison ignores the declared types of columns. [encoding] is as in {!Lower.query}, and a window key under BINARY orders under its sequence too.
The caller runs the scan and any grouping: an aggregate select folds with {!Ir.run_grouped} and passes the grouped rows, with [grouped] set to [true]. Then two rows that a descending [ORDER BY] key of the window compares equal come out in the reverse of their arrival order; otherwise, and for rows from a scan, ties keep their order.
@raise Ir.Unsupported for a projection that {!Lower} does not support. *)