Skip to main content

riffdb_types/
aggregate.rs

1//! Closed compiler-owned aggregate semantic vocabulary.
2//!
3//! These descriptors are transient compilation metadata. They are not encoded
4//! into query IR, provider state, plan hashes, wire messages, or generated SDK
5//! artifacts. Existing durable tags remain owned by their original formats.
6
7/// Maximum distinct canonical values retained by one exact measure/group.
8pub const MAX_AGGREGATE_DISTINCT_VALUES_V1: u16 = 256;
9/// Maximum transient aggregate partial-state bytes in one query result.
10pub const MAX_AGGREGATE_STATE_BYTES_V1: u32 = 1_048_576;
11/// Maximum exact contribution/merge arithmetic operations in one aggregate.
12pub const MAX_AGGREGATE_ARITHMETIC_OPERATIONS_V1: u32 = 8_192;
13
14/// Stable semantic identity for the aggregate functions available before
15/// ADR-0152 expansion.
16#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
17pub enum AggregateSemanticIdentityV1 {
18    /// Exact count of rows in an earlier bounded source.
19    Count,
20    /// Exact count of the complete provider-admitted population.
21    ExactCount,
22    /// Checked exact sum of one numeric field.
23    Sum,
24    /// Minimum under the field's frozen typed comparator.
25    Min,
26    /// Maximum under the field's frozen typed comparator.
27    Max,
28    /// Exact count of present values.
29    CountPresent,
30    /// Exact distinct count including `NoValue`.
31    CountDistinct,
32    /// Exact distinct count excluding `NoValue`.
33    CountDistinctPresent,
34    /// Exact total and contributing count without division.
35    Mean,
36    /// Boolean disjunction.
37    Any,
38    /// Boolean conjunction.
39    All,
40}
41
42impl AggregateSemanticIdentityV1 {
43    /// Looks up the semantic identity for one compiler-owned source spelling.
44    #[must_use]
45    pub fn from_source_spelling(spelling: &str) -> Option<Self> {
46        aggregate_semantic_registry_v1()
47            .iter()
48            .chain(SAAS_OPERATIONAL_AGGREGATE_REGISTRY_V1.iter())
49            .find(|descriptor| descriptor.source_spelling == spelling)
50            .map(|descriptor| descriptor.identity)
51    }
52
53    /// Returns this identity's complete v1 descriptor.
54    #[must_use]
55    pub const fn descriptor(self) -> &'static AggregateSemanticDescriptorV1 {
56        match self {
57            Self::Count => &AGGREGATE_SEMANTIC_REGISTRY_V1[0],
58            Self::ExactCount => &AGGREGATE_SEMANTIC_REGISTRY_V1[1],
59            Self::Sum => &AGGREGATE_SEMANTIC_REGISTRY_V1[2],
60            Self::Min => &AGGREGATE_SEMANTIC_REGISTRY_V1[3],
61            Self::Max => &AGGREGATE_SEMANTIC_REGISTRY_V1[4],
62            Self::CountPresent => &AGGREGATE_SEMANTIC_REGISTRY_V1[5],
63            Self::CountDistinct => &AGGREGATE_SEMANTIC_REGISTRY_V1[6],
64            Self::CountDistinctPresent => &AGGREGATE_SEMANTIC_REGISTRY_V1[7],
65            Self::Mean => &AGGREGATE_SEMANTIC_REGISTRY_V1[8],
66            Self::Any => &AGGREGATE_SEMANTIC_REGISTRY_V1[9],
67            Self::All => &AGGREGATE_SEMANTIC_REGISTRY_V1[10],
68        }
69    }
70}
71
72/// Closed exact aggregate semantics advertised by one provider descriptor.
73///
74/// The set is derived from the provider kind plus its sealed `MEASURE` stage;
75/// it is transient compatibility metadata and does not add a second durable
76/// descriptor encoding. New query/module identities still carry the selected
77/// aggregate semantics themselves.
78#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
79pub struct AggregateSemanticSetV1(u16);
80
81impl AggregateSemanticSetV1 {
82    /// No aggregate semantics are executable.
83    pub const NONE: Self = Self(0);
84    /// Exact functions implemented by the bounded/grouped columnar evaluator.
85    pub const BOUNDED_EXACT_CORE: Self = Self(
86        semantic_bit(AggregateSemanticIdentityV1::Count)
87            | semantic_bit(AggregateSemanticIdentityV1::Sum)
88            | semantic_bit(AggregateSemanticIdentityV1::Min)
89            | semantic_bit(AggregateSemanticIdentityV1::Max)
90            | semantic_bit(AggregateSemanticIdentityV1::CountPresent)
91            | semantic_bit(AggregateSemanticIdentityV1::CountDistinct)
92            | semantic_bit(AggregateSemanticIdentityV1::CountDistinctPresent)
93            | semantic_bit(AggregateSemanticIdentityV1::Mean)
94            | semantic_bit(AggregateSemanticIdentityV1::Any)
95            | semantic_bit(AggregateSemanticIdentityV1::All),
96    );
97    /// Exact whole-population cardinality implemented by the indexed exact
98    /// result provider.
99    pub const EXACT_COUNT_ONLY: Self = Self(semantic_bit(AggregateSemanticIdentityV1::ExactCount));
100
101    /// Whether this checked provider set contains one semantic identity.
102    #[must_use]
103    pub const fn contains(self, identity: AggregateSemanticIdentityV1) -> bool {
104        self.0 & semantic_bit(identity) != 0
105    }
106
107    /// Number of advertised exact semantic identities.
108    #[must_use]
109    pub const fn len(self) -> u32 {
110        self.0.count_ones()
111    }
112
113    /// Whether no aggregate semantic is advertised.
114    #[must_use]
115    pub const fn is_empty(self) -> bool {
116        self.0 == 0
117    }
118}
119
120const fn semantic_bit(identity: AggregateSemanticIdentityV1) -> u16 {
121    match identity {
122        AggregateSemanticIdentityV1::Count => 1 << 0,
123        AggregateSemanticIdentityV1::ExactCount => 1 << 1,
124        AggregateSemanticIdentityV1::Sum => 1 << 2,
125        AggregateSemanticIdentityV1::Min => 1 << 3,
126        AggregateSemanticIdentityV1::Max => 1 << 4,
127        AggregateSemanticIdentityV1::CountPresent => 1 << 5,
128        AggregateSemanticIdentityV1::CountDistinct => 1 << 6,
129        AggregateSemanticIdentityV1::CountDistinctPresent => 1 << 7,
130        AggregateSemanticIdentityV1::Mean => 1 << 8,
131        AggregateSemanticIdentityV1::Any => 1 << 9,
132        AggregateSemanticIdentityV1::All => 1 << 10,
133    }
134}
135
136/// Compiler-accepted input shape for one aggregate function.
137#[derive(Clone, Copy, Debug, Eq, PartialEq)]
138pub enum AggregateInputClassV1 {
139    /// The aggregate accepts no field argument.
140    NoField,
141    /// One required exact `i64`, `u64`, or fixed-decimal field.
142    ExactNumericField,
143    /// One ordered scalar field, including an optional field's `NoValue` state.
144    OrderedScalarField,
145    /// One scalar field with canonical typed equality.
146    CanonicalScalarField,
147    /// One required Boolean field.
148    RequiredBooleanField,
149}
150
151/// How the aggregate treats the canonical optional `NoValue` state.
152#[derive(Clone, Copy, Debug, Eq, PartialEq)]
153pub enum AggregateNoValueRuleV1 {
154    /// Field values are irrelevant and every admitted row contributes.
155    CountsRow,
156    /// An optional field is not an accepted input type.
157    InvalidInputType,
158    /// `NoValue` is a real value under the frozen typed comparator.
159    ComparableState,
160    /// `NoValue` does not contribute.
161    Excluded,
162    /// `NoValue` contributes as one canonical distinct value.
163    DistinctValue,
164}
165
166/// Exact result returned for an empty input population.
167#[derive(Clone, Copy, Debug, Eq, PartialEq)]
168pub enum AggregateEmptyResultV1 {
169    /// Unsigned cardinality zero.
170    UnsignedZero,
171    /// Exact additive zero at the compiler-resolved input scale.
172    ExactNumericZero,
173    /// Outer absence, distinct from a contributed `NoValue`.
174    Absent,
175    /// Exact mean state with zero total and zero count.
176    ExactMeanZero,
177    /// Boolean false.
178    BooleanFalse,
179    /// Boolean true.
180    BooleanTrue,
181}
182
183/// Compiler-resolved public result schema family.
184#[derive(Clone, Copy, Debug, Eq, PartialEq)]
185pub enum AggregateResultSchemaV1 {
186    /// Exact unsigned 64-bit cardinality.
187    U64,
188    /// Widened exact decimal retaining the input's fixed scale.
189    ExactDecimalAtInputScale,
190    /// Optional copy of the compiler-resolved input scalar type.
191    OptionalInputScalar,
192    /// Exact `ExactMeanV1 { total, count }` record.
193    ExactMeanV1,
194    /// Required Boolean scalar.
195    Bool,
196    /// Bounded list of the compiler-resolved non-optional input scalar type.
197    BoundedInputScalarList,
198}
199
200/// Mergeable partial-state family admitted by an exact provider.
201#[derive(Clone, Copy, Debug, Eq, PartialEq)]
202pub enum AggregatePartialStateV1 {
203    /// Checked unsigned 64-bit counter.
204    CheckedU64,
205    /// Checked signed 128-bit coefficient plus compiler-resolved scale.
206    CheckedI128AtInputScale,
207    /// Optional scalar selected using the frozen typed comparator.
208    OptionalOrderedScalar,
209    /// Bounded canonical typed value set.
210    BoundedCanonicalSet,
211    /// Checked exact total and unsigned count.
212    ExactMeanV1,
213    /// Boolean disjunction state.
214    BooleanAny,
215    /// Boolean conjunction state.
216    BooleanAll,
217}
218
219/// Arithmetic or comparison rule used by the exact evaluator.
220#[derive(Clone, Copy, Debug, Eq, PartialEq)]
221pub enum AggregateArithmeticV1 {
222    /// Checked unsigned 64-bit addition; overflow refuses the whole result.
223    CheckedU64,
224    /// Checked signed 128-bit addition; overflow refuses the whole result.
225    CheckedI128,
226    /// The input field's canonical frozen typed comparator.
227    FrozenTypedComparator,
228    /// Canonical typed equality with checked bounded-set growth.
229    CanonicalDistinctSet,
230    /// Checked exact total and checked unsigned count.
231    CheckedExactMean,
232    /// Boolean disjunction.
233    BooleanOr,
234    /// Boolean conjunction.
235    BooleanAnd,
236}
237
238/// Static execution-family eligibility for one aggregate semantic.
239#[derive(Clone, Copy, Debug, Eq, PartialEq)]
240pub struct AggregateEligibilityV1 {
241    ordinary_bounded_fold: bool,
242    grouped_bounded_fold: bool,
243    whole_result_provider: bool,
244}
245
246impl AggregateEligibilityV1 {
247    /// Whether the function may fold an earlier compiler-bounded collection.
248    #[must_use]
249    pub const fn ordinary_bounded_fold(self) -> bool {
250        self.ordinary_bounded_fold
251    }
252
253    /// Whether the function may fold compiler-bounded groups.
254    #[must_use]
255    pub const fn grouped_bounded_fold(self) -> bool {
256        self.grouped_bounded_fold
257    }
258
259    /// Whether an exact whole-result provider may advertise the function.
260    #[must_use]
261    pub const fn whole_result_provider(self) -> bool {
262        self.whole_result_provider
263    }
264}
265
266/// Where the maximum for one aggregate resource dimension is frozen.
267#[derive(Clone, Copy, Debug, Eq, PartialEq)]
268pub enum AggregateBudgetBoundV1 {
269    /// The function does not retain or consume this resource dimension.
270    NotApplicable,
271    /// The compiler seals a finite maximum into the complete plan.
272    CompilerPlan,
273    /// The compiler seals a finite maximum when the aggregate is grouped.
274    CompilerPlanWhenGrouped,
275}
276
277/// Budget dimensions which every plan using an aggregate must account for.
278#[derive(Clone, Copy, Debug, Eq, PartialEq)]
279pub struct AggregateBudgetDimensionsV1 {
280    input_rows: AggregateBudgetBoundV1,
281    distinct_values: AggregateBudgetBoundV1,
282    groups: AggregateBudgetBoundV1,
283    state_bytes: AggregateBudgetBoundV1,
284    output_bytes: AggregateBudgetBoundV1,
285    diagnostic_work: AggregateBudgetBoundV1,
286}
287
288impl AggregateBudgetDimensionsV1 {
289    /// Whether admitted input rows require a compiler/runtime charge.
290    #[must_use]
291    pub const fn charges_input_rows(self) -> bool {
292        !matches!(self.input_rows, AggregateBudgetBoundV1::NotApplicable)
293    }
294
295    /// Source of the maximum admitted input-row count.
296    #[must_use]
297    pub const fn input_rows(self) -> AggregateBudgetBoundV1 {
298        self.input_rows
299    }
300
301    /// Source of the maximum retained distinct-value count.
302    #[must_use]
303    pub const fn distinct_values(self) -> AggregateBudgetBoundV1 {
304        self.distinct_values
305    }
306
307    /// Whether group cardinality requires an independent bound when grouped.
308    #[must_use]
309    pub const fn charges_groups(self) -> bool {
310        !matches!(self.groups, AggregateBudgetBoundV1::NotApplicable)
311    }
312
313    /// Source of the maximum group count.
314    #[must_use]
315    pub const fn groups(self) -> AggregateBudgetBoundV1 {
316        self.groups
317    }
318
319    /// Whether partial aggregate state bytes require an independent bound.
320    #[must_use]
321    pub const fn charges_state_bytes(self) -> bool {
322        !matches!(self.state_bytes, AggregateBudgetBoundV1::NotApplicable)
323    }
324
325    /// Source of the maximum partial-state bytes.
326    #[must_use]
327    pub const fn state_bytes(self) -> AggregateBudgetBoundV1 {
328        self.state_bytes
329    }
330
331    /// Whether encoded aggregate output bytes require an independent bound.
332    #[must_use]
333    pub const fn charges_output_bytes(self) -> bool {
334        !matches!(self.output_bytes, AggregateBudgetBoundV1::NotApplicable)
335    }
336
337    /// Source of the maximum encoded output bytes.
338    #[must_use]
339    pub const fn output_bytes(self) -> AggregateBudgetBoundV1 {
340        self.output_bytes
341    }
342
343    /// Whether bounded diagnostic work must be accounted for.
344    #[must_use]
345    pub const fn charges_diagnostic_work(self) -> bool {
346        !matches!(self.diagnostic_work, AggregateBudgetBoundV1::NotApplicable)
347    }
348
349    /// Source of the maximum bounded diagnostic work.
350    #[must_use]
351    pub const fn diagnostic_work(self) -> AggregateBudgetBoundV1 {
352        self.diagnostic_work
353    }
354}
355
356/// Policy and inference posture shared by every existing exact aggregate.
357#[derive(Clone, Copy, Debug, Eq, PartialEq)]
358pub struct AggregatePolicyV1 {
359    admits_rows_before_aggregation: bool,
360    partition_scoped_primary: bool,
361    withholds_partial_results: bool,
362}
363
364impl AggregatePolicyV1 {
365    /// Whether row policy is applied before any fold, count, group, or limit.
366    #[must_use]
367    pub const fn admits_rows_before_aggregation(self) -> bool {
368        self.admits_rows_before_aggregation
369    }
370
371    /// Whether policy-aligned provider partitioning is the primary mode.
372    #[must_use]
373    pub const fn partition_scoped_primary(self) -> bool {
374        self.partition_scoped_primary
375    }
376
377    /// Whether refusal or budget exhaustion releases no partial aggregate.
378    #[must_use]
379    pub const fn withholds_partial_results(self) -> bool {
380        self.withholds_partial_results
381    }
382}
383
384/// Complete transient semantic descriptor for one exact aggregate function.
385#[derive(Clone, Copy, Debug, Eq, PartialEq)]
386pub struct AggregateSemanticDescriptorV1 {
387    identity: AggregateSemanticIdentityV1,
388    source_spelling: &'static str,
389    input_class: AggregateInputClassV1,
390    no_value_rule: AggregateNoValueRuleV1,
391    empty_result: AggregateEmptyResultV1,
392    result_schema: AggregateResultSchemaV1,
393    partial_state: AggregatePartialStateV1,
394    arithmetic: AggregateArithmeticV1,
395    operational_ir_tag: Option<u8>,
396    eligibility: AggregateEligibilityV1,
397    budgets: AggregateBudgetDimensionsV1,
398    policy: AggregatePolicyV1,
399}
400
401impl AggregateSemanticDescriptorV1 {
402    /// Stable semantic identity.
403    #[must_use]
404    pub const fn identity(self) -> AggregateSemanticIdentityV1 {
405        self.identity
406    }
407
408    /// Exact RiffQL source spelling.
409    #[must_use]
410    pub const fn source_spelling(self) -> &'static str {
411        self.source_spelling
412    }
413
414    /// Compiler-accepted input class and arity.
415    #[must_use]
416    pub const fn input_class(self) -> AggregateInputClassV1 {
417        self.input_class
418    }
419
420    /// Canonical `NoValue` rule.
421    #[must_use]
422    pub const fn no_value_rule(self) -> AggregateNoValueRuleV1 {
423        self.no_value_rule
424    }
425
426    /// Empty-population result.
427    #[must_use]
428    pub const fn empty_result(self) -> AggregateEmptyResultV1 {
429        self.empty_result
430    }
431
432    /// Compiler-resolved public result schema family.
433    #[must_use]
434    pub const fn result_schema(self) -> AggregateResultSchemaV1 {
435        self.result_schema
436    }
437
438    /// Mergeable exact partial-state family.
439    #[must_use]
440    pub const fn partial_state(self) -> AggregatePartialStateV1 {
441        self.partial_state
442    }
443
444    /// Exact arithmetic or comparison rule.
445    #[must_use]
446    pub const fn arithmetic(self) -> AggregateArithmeticV1 {
447        self.arithmetic
448    }
449
450    /// Existing durable operational query-IR tag, when this semantic is
451    /// carried by that format. These values are inventory only and unchanged.
452    #[must_use]
453    pub const fn operational_ir_tag(self) -> Option<u8> {
454        self.operational_ir_tag
455    }
456
457    /// Static execution-family eligibility.
458    #[must_use]
459    pub const fn eligibility(self) -> AggregateEligibilityV1 {
460        self.eligibility
461    }
462
463    /// Required independent budget dimensions.
464    #[must_use]
465    pub const fn budgets(self) -> AggregateBudgetDimensionsV1 {
466        self.budgets
467    }
468
469    /// Policy and inference posture.
470    #[must_use]
471    pub const fn policy(self) -> AggregatePolicyV1 {
472        self.policy
473    }
474}
475
476const BOUNDED_AND_PROVIDER: AggregateEligibilityV1 = AggregateEligibilityV1 {
477    ordinary_bounded_fold: true,
478    grouped_bounded_fold: true,
479    whole_result_provider: true,
480};
481
482const WHOLE_RESULT_ONLY: AggregateEligibilityV1 = AggregateEligibilityV1 {
483    ordinary_bounded_fold: false,
484    grouped_bounded_fold: false,
485    whole_result_provider: true,
486};
487
488const EXACT_BUDGETS: AggregateBudgetDimensionsV1 = AggregateBudgetDimensionsV1 {
489    input_rows: AggregateBudgetBoundV1::CompilerPlan,
490    distinct_values: AggregateBudgetBoundV1::NotApplicable,
491    groups: AggregateBudgetBoundV1::CompilerPlanWhenGrouped,
492    state_bytes: AggregateBudgetBoundV1::CompilerPlan,
493    output_bytes: AggregateBudgetBoundV1::CompilerPlan,
494    diagnostic_work: AggregateBudgetBoundV1::CompilerPlan,
495};
496
497const EXACT_COUNT_BUDGETS: AggregateBudgetDimensionsV1 = AggregateBudgetDimensionsV1 {
498    input_rows: AggregateBudgetBoundV1::CompilerPlan,
499    distinct_values: AggregateBudgetBoundV1::NotApplicable,
500    groups: AggregateBudgetBoundV1::NotApplicable,
501    state_bytes: AggregateBudgetBoundV1::CompilerPlan,
502    output_bytes: AggregateBudgetBoundV1::CompilerPlan,
503    diagnostic_work: AggregateBudgetBoundV1::CompilerPlan,
504};
505
506const EXACT_DISTINCT_BUDGETS: AggregateBudgetDimensionsV1 = AggregateBudgetDimensionsV1 {
507    input_rows: AggregateBudgetBoundV1::CompilerPlan,
508    distinct_values: AggregateBudgetBoundV1::CompilerPlan,
509    groups: AggregateBudgetBoundV1::CompilerPlanWhenGrouped,
510    state_bytes: AggregateBudgetBoundV1::CompilerPlan,
511    output_bytes: AggregateBudgetBoundV1::CompilerPlan,
512    diagnostic_work: AggregateBudgetBoundV1::CompilerPlan,
513};
514
515const EXACT_POLICY: AggregatePolicyV1 = AggregatePolicyV1 {
516    admits_rows_before_aggregation: true,
517    partition_scoped_primary: true,
518    withholds_partial_results: true,
519};
520
521const AGGREGATE_SEMANTIC_REGISTRY_V1: [AggregateSemanticDescriptorV1; 11] = [
522    AggregateSemanticDescriptorV1 {
523        identity: AggregateSemanticIdentityV1::Count,
524        source_spelling: "count",
525        input_class: AggregateInputClassV1::NoField,
526        no_value_rule: AggregateNoValueRuleV1::CountsRow,
527        empty_result: AggregateEmptyResultV1::UnsignedZero,
528        result_schema: AggregateResultSchemaV1::U64,
529        partial_state: AggregatePartialStateV1::CheckedU64,
530        arithmetic: AggregateArithmeticV1::CheckedU64,
531        operational_ir_tag: Some(1),
532        eligibility: BOUNDED_AND_PROVIDER,
533        budgets: EXACT_BUDGETS,
534        policy: EXACT_POLICY,
535    },
536    AggregateSemanticDescriptorV1 {
537        identity: AggregateSemanticIdentityV1::ExactCount,
538        source_spelling: "exact_count",
539        input_class: AggregateInputClassV1::NoField,
540        no_value_rule: AggregateNoValueRuleV1::CountsRow,
541        empty_result: AggregateEmptyResultV1::UnsignedZero,
542        result_schema: AggregateResultSchemaV1::U64,
543        partial_state: AggregatePartialStateV1::CheckedU64,
544        arithmetic: AggregateArithmeticV1::CheckedU64,
545        operational_ir_tag: None,
546        eligibility: WHOLE_RESULT_ONLY,
547        budgets: EXACT_COUNT_BUDGETS,
548        policy: EXACT_POLICY,
549    },
550    AggregateSemanticDescriptorV1 {
551        identity: AggregateSemanticIdentityV1::Sum,
552        source_spelling: "sum",
553        input_class: AggregateInputClassV1::ExactNumericField,
554        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
555        empty_result: AggregateEmptyResultV1::ExactNumericZero,
556        result_schema: AggregateResultSchemaV1::ExactDecimalAtInputScale,
557        partial_state: AggregatePartialStateV1::CheckedI128AtInputScale,
558        arithmetic: AggregateArithmeticV1::CheckedI128,
559        operational_ir_tag: Some(2),
560        eligibility: BOUNDED_AND_PROVIDER,
561        budgets: EXACT_BUDGETS,
562        policy: EXACT_POLICY,
563    },
564    AggregateSemanticDescriptorV1 {
565        identity: AggregateSemanticIdentityV1::Min,
566        source_spelling: "min",
567        input_class: AggregateInputClassV1::OrderedScalarField,
568        no_value_rule: AggregateNoValueRuleV1::ComparableState,
569        empty_result: AggregateEmptyResultV1::Absent,
570        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
571        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
572        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
573        operational_ir_tag: Some(3),
574        eligibility: BOUNDED_AND_PROVIDER,
575        budgets: EXACT_BUDGETS,
576        policy: EXACT_POLICY,
577    },
578    AggregateSemanticDescriptorV1 {
579        identity: AggregateSemanticIdentityV1::Max,
580        source_spelling: "max",
581        input_class: AggregateInputClassV1::OrderedScalarField,
582        no_value_rule: AggregateNoValueRuleV1::ComparableState,
583        empty_result: AggregateEmptyResultV1::Absent,
584        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
585        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
586        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
587        operational_ir_tag: Some(4),
588        eligibility: BOUNDED_AND_PROVIDER,
589        budgets: EXACT_BUDGETS,
590        policy: EXACT_POLICY,
591    },
592    AggregateSemanticDescriptorV1 {
593        identity: AggregateSemanticIdentityV1::CountPresent,
594        source_spelling: "count_present",
595        input_class: AggregateInputClassV1::CanonicalScalarField,
596        no_value_rule: AggregateNoValueRuleV1::Excluded,
597        empty_result: AggregateEmptyResultV1::UnsignedZero,
598        result_schema: AggregateResultSchemaV1::U64,
599        partial_state: AggregatePartialStateV1::CheckedU64,
600        arithmetic: AggregateArithmeticV1::CheckedU64,
601        operational_ir_tag: Some(5),
602        eligibility: BOUNDED_AND_PROVIDER,
603        budgets: EXACT_BUDGETS,
604        policy: EXACT_POLICY,
605    },
606    AggregateSemanticDescriptorV1 {
607        identity: AggregateSemanticIdentityV1::CountDistinct,
608        source_spelling: "count_distinct",
609        input_class: AggregateInputClassV1::CanonicalScalarField,
610        no_value_rule: AggregateNoValueRuleV1::DistinctValue,
611        empty_result: AggregateEmptyResultV1::UnsignedZero,
612        result_schema: AggregateResultSchemaV1::U64,
613        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
614        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
615        operational_ir_tag: Some(6),
616        eligibility: BOUNDED_AND_PROVIDER,
617        budgets: EXACT_DISTINCT_BUDGETS,
618        policy: EXACT_POLICY,
619    },
620    AggregateSemanticDescriptorV1 {
621        identity: AggregateSemanticIdentityV1::CountDistinctPresent,
622        source_spelling: "count_distinct_present",
623        input_class: AggregateInputClassV1::CanonicalScalarField,
624        no_value_rule: AggregateNoValueRuleV1::Excluded,
625        empty_result: AggregateEmptyResultV1::UnsignedZero,
626        result_schema: AggregateResultSchemaV1::U64,
627        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
628        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
629        operational_ir_tag: Some(7),
630        eligibility: BOUNDED_AND_PROVIDER,
631        budgets: EXACT_DISTINCT_BUDGETS,
632        policy: EXACT_POLICY,
633    },
634    AggregateSemanticDescriptorV1 {
635        identity: AggregateSemanticIdentityV1::Mean,
636        source_spelling: "mean",
637        input_class: AggregateInputClassV1::ExactNumericField,
638        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
639        empty_result: AggregateEmptyResultV1::ExactMeanZero,
640        result_schema: AggregateResultSchemaV1::ExactMeanV1,
641        partial_state: AggregatePartialStateV1::ExactMeanV1,
642        arithmetic: AggregateArithmeticV1::CheckedExactMean,
643        operational_ir_tag: Some(8),
644        eligibility: BOUNDED_AND_PROVIDER,
645        budgets: EXACT_BUDGETS,
646        policy: EXACT_POLICY,
647    },
648    AggregateSemanticDescriptorV1 {
649        identity: AggregateSemanticIdentityV1::Any,
650        source_spelling: "any",
651        input_class: AggregateInputClassV1::RequiredBooleanField,
652        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
653        empty_result: AggregateEmptyResultV1::BooleanFalse,
654        result_schema: AggregateResultSchemaV1::Bool,
655        partial_state: AggregatePartialStateV1::BooleanAny,
656        arithmetic: AggregateArithmeticV1::BooleanOr,
657        operational_ir_tag: Some(9),
658        eligibility: BOUNDED_AND_PROVIDER,
659        budgets: EXACT_BUDGETS,
660        policy: EXACT_POLICY,
661    },
662    AggregateSemanticDescriptorV1 {
663        identity: AggregateSemanticIdentityV1::All,
664        source_spelling: "all",
665        input_class: AggregateInputClassV1::RequiredBooleanField,
666        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
667        empty_result: AggregateEmptyResultV1::BooleanTrue,
668        result_schema: AggregateResultSchemaV1::Bool,
669        partial_state: AggregatePartialStateV1::BooleanAll,
670        arithmetic: AggregateArithmeticV1::BooleanAnd,
671        operational_ir_tag: Some(10),
672        eligibility: BOUNDED_AND_PROVIDER,
673        budgets: EXACT_BUDGETS,
674        policy: EXACT_POLICY,
675    },
676];
677
678const BOUNDED_FOLD_ONLY: AggregateEligibilityV1 = AggregateEligibilityV1 {
679    ordinary_bounded_fold: true,
680    grouped_bounded_fold: true,
681    whole_result_provider: false,
682};
683
684const SAAS_OPERATIONAL_AGGREGATE_REGISTRY_V1: [AggregateSemanticDescriptorV1; 9] = [
685    AggregateSemanticDescriptorV1 {
686        identity: AggregateSemanticIdentityV1::Min,
687        source_spelling: "median",
688        input_class: AggregateInputClassV1::OrderedScalarField,
689        no_value_rule: AggregateNoValueRuleV1::Excluded,
690        empty_result: AggregateEmptyResultV1::Absent,
691        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
692        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
693        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
694        operational_ir_tag: Some(11),
695        eligibility: BOUNDED_FOLD_ONLY,
696        budgets: EXACT_BUDGETS,
697        policy: EXACT_POLICY,
698    },
699    AggregateSemanticDescriptorV1 {
700        identity: AggregateSemanticIdentityV1::Min,
701        source_spelling: "p90",
702        input_class: AggregateInputClassV1::OrderedScalarField,
703        no_value_rule: AggregateNoValueRuleV1::Excluded,
704        empty_result: AggregateEmptyResultV1::Absent,
705        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
706        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
707        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
708        operational_ir_tag: Some(12),
709        eligibility: BOUNDED_FOLD_ONLY,
710        budgets: EXACT_BUDGETS,
711        policy: EXACT_POLICY,
712    },
713    AggregateSemanticDescriptorV1 {
714        identity: AggregateSemanticIdentityV1::Min,
715        source_spelling: "p95",
716        input_class: AggregateInputClassV1::OrderedScalarField,
717        no_value_rule: AggregateNoValueRuleV1::Excluded,
718        empty_result: AggregateEmptyResultV1::Absent,
719        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
720        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
721        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
722        operational_ir_tag: Some(13),
723        eligibility: BOUNDED_FOLD_ONLY,
724        budgets: EXACT_BUDGETS,
725        policy: EXACT_POLICY,
726    },
727    AggregateSemanticDescriptorV1 {
728        identity: AggregateSemanticIdentityV1::Min,
729        source_spelling: "p99",
730        input_class: AggregateInputClassV1::OrderedScalarField,
731        no_value_rule: AggregateNoValueRuleV1::Excluded,
732        empty_result: AggregateEmptyResultV1::Absent,
733        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
734        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
735        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
736        operational_ir_tag: Some(14),
737        eligibility: BOUNDED_FOLD_ONLY,
738        budgets: EXACT_BUDGETS,
739        policy: EXACT_POLICY,
740    },
741    AggregateSemanticDescriptorV1 {
742        identity: AggregateSemanticIdentityV1::Min,
743        source_spelling: "first",
744        input_class: AggregateInputClassV1::CanonicalScalarField,
745        no_value_rule: AggregateNoValueRuleV1::Excluded,
746        empty_result: AggregateEmptyResultV1::Absent,
747        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
748        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
749        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
750        operational_ir_tag: Some(15),
751        eligibility: BOUNDED_FOLD_ONLY,
752        budgets: EXACT_BUDGETS,
753        policy: EXACT_POLICY,
754    },
755    AggregateSemanticDescriptorV1 {
756        identity: AggregateSemanticIdentityV1::Max,
757        source_spelling: "last",
758        input_class: AggregateInputClassV1::CanonicalScalarField,
759        no_value_rule: AggregateNoValueRuleV1::Excluded,
760        empty_result: AggregateEmptyResultV1::Absent,
761        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
762        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
763        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
764        operational_ir_tag: Some(16),
765        eligibility: BOUNDED_FOLD_ONLY,
766        budgets: EXACT_BUDGETS,
767        policy: EXACT_POLICY,
768    },
769    AggregateSemanticDescriptorV1 {
770        identity: AggregateSemanticIdentityV1::Sum,
771        source_spelling: "stddev",
772        input_class: AggregateInputClassV1::ExactNumericField,
773        no_value_rule: AggregateNoValueRuleV1::Excluded,
774        empty_result: AggregateEmptyResultV1::ExactNumericZero,
775        result_schema: AggregateResultSchemaV1::ExactDecimalAtInputScale,
776        partial_state: AggregatePartialStateV1::CheckedI128AtInputScale,
777        arithmetic: AggregateArithmeticV1::CheckedI128,
778        operational_ir_tag: Some(17),
779        eligibility: BOUNDED_FOLD_ONLY,
780        budgets: EXACT_BUDGETS,
781        policy: EXACT_POLICY,
782    },
783    AggregateSemanticDescriptorV1 {
784        identity: AggregateSemanticIdentityV1::CountPresent,
785        source_spelling: "collect",
786        input_class: AggregateInputClassV1::CanonicalScalarField,
787        no_value_rule: AggregateNoValueRuleV1::Excluded,
788        empty_result: AggregateEmptyResultV1::UnsignedZero,
789        result_schema: AggregateResultSchemaV1::BoundedInputScalarList,
790        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
791        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
792        operational_ir_tag: Some(18),
793        eligibility: BOUNDED_FOLD_ONLY,
794        budgets: EXACT_DISTINCT_BUDGETS,
795        policy: EXACT_POLICY,
796    },
797    AggregateSemanticDescriptorV1 {
798        identity: AggregateSemanticIdentityV1::CountDistinctPresent,
799        source_spelling: "collect_distinct",
800        input_class: AggregateInputClassV1::CanonicalScalarField,
801        no_value_rule: AggregateNoValueRuleV1::Excluded,
802        empty_result: AggregateEmptyResultV1::UnsignedZero,
803        result_schema: AggregateResultSchemaV1::BoundedInputScalarList,
804        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
805        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
806        operational_ir_tag: Some(19),
807        eligibility: BOUNDED_FOLD_ONLY,
808        budgets: EXACT_DISTINCT_BUDGETS,
809        policy: EXACT_POLICY,
810    },
811];
812
813/// Returns the closed v1 aggregate semantic registry in stable identity order.
814#[must_use]
815pub const fn aggregate_semantic_registry_v1() -> &'static [AggregateSemanticDescriptorV1] {
816    &AGGREGATE_SEMANTIC_REGISTRY_V1
817}