11use std:: rc:: Rc ;
22use std:: time:: Duration ;
33
4- use crate :: types:: AccuracyTarget ;
54use super :: schema:: { HasSchema , L3Schema , SchemaCatalog } ;
5+ use crate :: types:: AccuracyTarget ;
66
77// ── Stub leaf / supporting types ──────────────────────────────────────────────
88// Full definitions will be added as the respective layers are implemented.
99
1010/// A row-level filter predicate (WHERE clause / PromQL label matcher).
11- #[ derive( Debug , Clone ) ] pub struct Predicate ;
11+ #[ derive( Debug , Clone ) ]
12+ pub struct Predicate ;
1213/// One item in a SELECT projection list.
13- #[ derive( Debug , Clone ) ] pub struct ProjectItem ;
14+ #[ derive( Debug , Clone ) ]
15+ pub struct ProjectItem ;
1416/// A GROUP BY key reference.
15- #[ derive( Debug , Clone ) ] pub struct GroupKey ;
17+ #[ derive( Debug , Clone ) ]
18+ pub struct GroupKey ;
1619/// A reference to a column by name.
17- #[ derive( Debug , Clone ) ] pub struct ColumnRef ;
20+ #[ derive( Debug , Clone ) ]
21+ pub struct ColumnRef ;
1822/// A set of partitioning keys (sharding hint for L5 stage allocator).
19- #[ derive( Debug , Clone ) ] pub struct PartitionKeys ;
23+ #[ derive( Debug , Clone ) ]
24+ pub struct PartitionKeys ;
2025/// One key in an ORDER BY clause.
21- #[ derive( Debug , Clone ) ] pub struct SortKey ;
26+ #[ derive( Debug , Clone ) ]
27+ pub struct SortKey ;
2228/// An analytic window frame (ROWS / RANGE BETWEEN …).
23- #[ derive( Debug , Clone ) ] pub struct WindowFrame ;
29+ #[ derive( Debug , Clone ) ]
30+ pub struct WindowFrame ;
2431/// PromQL vector-match modifiers (`on`/`ignoring` + `group_left`/`group_right`).
25- #[ derive( Debug , Clone ) ] pub struct VectorMatch ;
32+ #[ derive( Debug , Clone ) ]
33+ pub struct VectorMatch ;
2634/// Reference to a metric by name (PromQL / OTLP).
27- #[ derive( Debug , Clone ) ] pub struct MetricRef ;
35+ #[ derive( Debug , Clone ) ]
36+ pub struct MetricRef ;
2837/// Closed time interval for a time-series scan.
29- #[ derive( Debug , Clone ) ] pub struct TimeRange ;
38+ #[ derive( Debug , Clone ) ]
39+ pub struct TimeRange ;
3040/// Label matchers applied to a time-series scan.
31- #[ derive( Debug , Clone ) ] pub struct LabelFilter ;
41+ #[ derive( Debug , Clone ) ]
42+ pub struct LabelFilter ;
3243/// Reference to a relational table by name.
33- #[ derive( Debug , Clone ) ] pub struct TableRef ;
44+ #[ derive( Debug , Clone ) ]
45+ pub struct TableRef ;
3446/// Join key specification (USING / ON column reference).
35- #[ derive( Debug , Clone ) ] pub struct JoinKey ;
47+ #[ derive( Debug , Clone ) ]
48+ pub struct JoinKey ;
3649
3750// ── Enum supporting types ─────────────────────────────────────────────────────
3851
@@ -55,20 +68,39 @@ pub enum SetOpKind {
5568#[ derive( Debug , Clone , PartialEq , Eq ) ]
5669pub enum BinaryOpKind {
5770 // Arithmetic
58- Add , Sub , Mul , Div , Mod ,
71+ Add ,
72+ Sub ,
73+ Mul ,
74+ Div ,
75+ Mod ,
5976 // Comparison
60- Eq , NotEq , Lt , LtEq , Gt , GtEq ,
77+ Eq ,
78+ NotEq ,
79+ Lt ,
80+ LtEq ,
81+ Gt ,
82+ GtEq ,
6183 // Boolean / PromQL set operators
62- And , Or , Unless ,
84+ And ,
85+ Or ,
86+ Unless ,
6387}
6488
6589#[ derive( Debug , Clone , PartialEq , Eq ) ]
6690pub enum WindowFuncKind {
67- RowNumber , Rank , DenseRank ,
68- Lag , Lead ,
69- FirstValue , LastValue ,
91+ RowNumber ,
92+ Rank ,
93+ DenseRank ,
94+ Lag ,
95+ Lead ,
96+ FirstValue ,
97+ LastValue ,
7098 NthValue ( u64 ) ,
71- Sum , Avg , Count , Min , Max ,
99+ Sum ,
100+ Avg ,
101+ Count ,
102+ Min ,
103+ Max ,
72104}
73105
74106/// Which data model a `Source` or `AggIntent` operates over.
@@ -141,23 +173,38 @@ impl Source {
141173#[ derive( Debug , Clone ) ]
142174pub enum AggIntent {
143175 // ── Data-model-agnostic ───────────────────────────────────────────────────
144- Count { accuracy : AccuracyTarget } ,
176+ Count {
177+ accuracy : AccuracyTarget ,
178+ } ,
145179 Sum ,
146180 Min ,
147181 Max ,
148- Quantile { q : f64 , accuracy : AccuracyTarget } ,
182+ Quantile {
183+ q : f64 ,
184+ accuracy : AccuracyTarget ,
185+ } ,
149186 /// Heavy-hitter top-k. Distinct from generic `Sort + Limit` — a
150187 /// dedicated sketch (SpaceSaving, CMS-with-heap) computes it as a single
151188 /// primitive. Recognised by L1→L2→L3 lowering on `ORDER BY count DESC
152189 /// LIMIT k` / PromQL `topk(k, …)`.
153- TopK { k : usize , by : Vec < ColumnRef > , accuracy : AccuracyTarget } ,
154- Cardinality { accuracy : AccuracyTarget } ,
190+ TopK {
191+ k : usize ,
192+ by : Vec < ColumnRef > ,
193+ accuracy : AccuracyTarget ,
194+ } ,
195+ Cardinality {
196+ accuracy : AccuracyTarget ,
197+ } ,
155198
156199 // ── Time-series streaming derivatives ────────────────────────────────────
157200 // Include PromQL counter-reset adjustment; not equivalent to Sum/Count
158201 // over a Window. Kept distinct so delta-set aggregators bind directly.
159- Rate { window : Duration } ,
160- Increase { window : Duration } ,
202+ Rate {
203+ window : Duration ,
204+ } ,
205+ Increase {
206+ window : Duration ,
207+ } ,
161208}
162209
163210impl AggIntent {
@@ -197,15 +244,24 @@ pub struct L3Node {
197244pub enum QueryExpr {
198245 // ── Base relations ────────────────────────────────────────────────────────
199246 /// Outermost leaf. `source` carries the data-model-specific leaf shape.
200- Scan { source : Source , predicates : Vec < Predicate > } ,
247+ Scan {
248+ source : Source ,
249+ predicates : Vec < Predicate > ,
250+ } ,
201251 /// Reference to a named `LetBinding` sub-expression; resolved at plan time.
202252 Ref ( String ) ,
203253
204254 // ── Filtering & projection ────────────────────────────────────────────────
205255 /// σ — row-level filter. Output schema = child schema (unchanged).
206- Filter { child : Rc < L3Node > , pred : Predicate } ,
256+ Filter {
257+ child : Rc < L3Node > ,
258+ pred : Predicate ,
259+ } ,
207260 /// π — column projection. Output schema = child schema projected to `cols`.
208- Project { child : Rc < L3Node > , cols : Vec < ProjectItem > } ,
261+ Project {
262+ child : Rc < L3Node > ,
263+ cols : Vec < ProjectItem > ,
264+ } ,
209265
210266 // ── Aggregation ───────────────────────────────────────────────────────────
211267 /// γ + α — GROUP BY + aggregate intents. Concrete operator (HashAgg /
@@ -231,13 +287,21 @@ pub enum QueryExpr {
231287 // ── Distributed-execution structure ───────────────────────────────────────
232288 /// Logical-only partitioning marker. Output schema = child schema.
233289 /// Carries a sharding hint for the L5 stage allocator.
234- Partition { child : Rc < L3Node > , keys : PartitionKeys } ,
290+ Partition {
291+ child : Rc < L3Node > ,
292+ keys : PartitionKeys ,
293+ } ,
235294 /// δ — SQL `DISTINCT` / row deduplication.
236- Distinct { child : Rc < L3Node > , cols : Vec < ColumnRef > } ,
295+ Distinct {
296+ child : Rc < L3Node > ,
297+ cols : Vec < ColumnRef > ,
298+ } ,
237299 /// ⊕ — exact union of sub-results from independent stages or shards.
238300 /// Sketch unions are a separate node in `SummaryExpr` because they carry
239301 /// sketch-family / params type constraints.
240- Merge { children : Vec < Rc < L3Node > > } ,
302+ Merge {
303+ children : Vec < Rc < L3Node > > ,
304+ } ,
241305
242306 // ── Joins ─────────────────────────────────────────────────────────────────
243307 /// Logical join. L4 picks the physical alternative (HashJoin /
@@ -261,11 +325,21 @@ pub enum QueryExpr {
261325 // ── Ordering & limiting ───────────────────────────────────────────────────
262326 /// Generic order-by for non-heavy-hitter cases (`ORDER BY name LIMIT 10`).
263327 /// Heavy-hitter shapes lower to `AggIntent::TopK` instead.
264- Sort { child : Rc < L3Node > , keys : Vec < SortKey > } ,
265- Limit { child : Rc < L3Node > , n : u64 , offset : u64 } ,
328+ Sort {
329+ child : Rc < L3Node > ,
330+ keys : Vec < SortKey > ,
331+ } ,
332+ Limit {
333+ child : Rc < L3Node > ,
334+ n : u64 ,
335+ offset : u64 ,
336+ } ,
266337
267338 // ── Subquery / CTE ────────────────────────────────────────────────────────
268- Subquery { child : Rc < L3Node > , alias : String } ,
339+ Subquery {
340+ child : Rc < L3Node > ,
341+ alias : String ,
342+ } ,
269343 /// SQL `WITH name AS (expr) … body`; lowering target for PromQL
270344 /// recording-rule bindings. The `expr` sub-DAG may be referenced N times
271345 /// via `Ref(name)` in `body`, giving the DAG its fan-in.
0 commit comments