riffdb-types 0.1.0

First-party RiffDB runtime crate (riffdb-types)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
//! Closed compiler-owned aggregate semantic vocabulary.
//!
//! These descriptors are transient compilation metadata. They are not encoded
//! into query IR, provider state, plan hashes, wire messages, or generated SDK
//! artifacts. Existing durable tags remain owned by their original formats.

/// Maximum distinct canonical values retained by one exact measure/group.
pub const MAX_AGGREGATE_DISTINCT_VALUES_V1: u16 = 256;
/// Maximum transient aggregate partial-state bytes in one query result.
pub const MAX_AGGREGATE_STATE_BYTES_V1: u32 = 1_048_576;
/// Maximum exact contribution/merge arithmetic operations in one aggregate.
pub const MAX_AGGREGATE_ARITHMETIC_OPERATIONS_V1: u32 = 8_192;

/// Stable semantic identity for the aggregate functions available before
/// ADR-0152 expansion.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum AggregateSemanticIdentityV1 {
    /// Exact count of rows in an earlier bounded source.
    Count,
    /// Exact count of the complete provider-admitted population.
    ExactCount,
    /// Checked exact sum of one numeric field.
    Sum,
    /// Minimum under the field's frozen typed comparator.
    Min,
    /// Maximum under the field's frozen typed comparator.
    Max,
    /// Exact count of present values.
    CountPresent,
    /// Exact distinct count including `NoValue`.
    CountDistinct,
    /// Exact distinct count excluding `NoValue`.
    CountDistinctPresent,
    /// Exact total and contributing count without division.
    Mean,
    /// Boolean disjunction.
    Any,
    /// Boolean conjunction.
    All,
}

impl AggregateSemanticIdentityV1 {
    /// Looks up the semantic identity for one compiler-owned source spelling.
    #[must_use]
    pub fn from_source_spelling(spelling: &str) -> Option<Self> {
        aggregate_semantic_registry_v1()
            .iter()
            .chain(SAAS_OPERATIONAL_AGGREGATE_REGISTRY_V1.iter())
            .find(|descriptor| descriptor.source_spelling == spelling)
            .map(|descriptor| descriptor.identity)
    }

    /// Returns this identity's complete v1 descriptor.
    #[must_use]
    pub const fn descriptor(self) -> &'static AggregateSemanticDescriptorV1 {
        match self {
            Self::Count => &AGGREGATE_SEMANTIC_REGISTRY_V1[0],
            Self::ExactCount => &AGGREGATE_SEMANTIC_REGISTRY_V1[1],
            Self::Sum => &AGGREGATE_SEMANTIC_REGISTRY_V1[2],
            Self::Min => &AGGREGATE_SEMANTIC_REGISTRY_V1[3],
            Self::Max => &AGGREGATE_SEMANTIC_REGISTRY_V1[4],
            Self::CountPresent => &AGGREGATE_SEMANTIC_REGISTRY_V1[5],
            Self::CountDistinct => &AGGREGATE_SEMANTIC_REGISTRY_V1[6],
            Self::CountDistinctPresent => &AGGREGATE_SEMANTIC_REGISTRY_V1[7],
            Self::Mean => &AGGREGATE_SEMANTIC_REGISTRY_V1[8],
            Self::Any => &AGGREGATE_SEMANTIC_REGISTRY_V1[9],
            Self::All => &AGGREGATE_SEMANTIC_REGISTRY_V1[10],
        }
    }
}

/// Closed exact aggregate semantics advertised by one provider descriptor.
///
/// The set is derived from the provider kind plus its sealed `MEASURE` stage;
/// it is transient compatibility metadata and does not add a second durable
/// descriptor encoding. New query/module identities still carry the selected
/// aggregate semantics themselves.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct AggregateSemanticSetV1(u16);

impl AggregateSemanticSetV1 {
    /// No aggregate semantics are executable.
    pub const NONE: Self = Self(0);
    /// Exact functions implemented by the bounded/grouped columnar evaluator.
    pub const BOUNDED_EXACT_CORE: Self = Self(
        semantic_bit(AggregateSemanticIdentityV1::Count)
            | semantic_bit(AggregateSemanticIdentityV1::Sum)
            | semantic_bit(AggregateSemanticIdentityV1::Min)
            | semantic_bit(AggregateSemanticIdentityV1::Max)
            | semantic_bit(AggregateSemanticIdentityV1::CountPresent)
            | semantic_bit(AggregateSemanticIdentityV1::CountDistinct)
            | semantic_bit(AggregateSemanticIdentityV1::CountDistinctPresent)
            | semantic_bit(AggregateSemanticIdentityV1::Mean)
            | semantic_bit(AggregateSemanticIdentityV1::Any)
            | semantic_bit(AggregateSemanticIdentityV1::All),
    );
    /// Exact whole-population cardinality implemented by the indexed exact
    /// result provider.
    pub const EXACT_COUNT_ONLY: Self = Self(semantic_bit(AggregateSemanticIdentityV1::ExactCount));

    /// Whether this checked provider set contains one semantic identity.
    #[must_use]
    pub const fn contains(self, identity: AggregateSemanticIdentityV1) -> bool {
        self.0 & semantic_bit(identity) != 0
    }

    /// Number of advertised exact semantic identities.
    #[must_use]
    pub const fn len(self) -> u32 {
        self.0.count_ones()
    }

    /// Whether no aggregate semantic is advertised.
    #[must_use]
    pub const fn is_empty(self) -> bool {
        self.0 == 0
    }
}

const fn semantic_bit(identity: AggregateSemanticIdentityV1) -> u16 {
    match identity {
        AggregateSemanticIdentityV1::Count => 1 << 0,
        AggregateSemanticIdentityV1::ExactCount => 1 << 1,
        AggregateSemanticIdentityV1::Sum => 1 << 2,
        AggregateSemanticIdentityV1::Min => 1 << 3,
        AggregateSemanticIdentityV1::Max => 1 << 4,
        AggregateSemanticIdentityV1::CountPresent => 1 << 5,
        AggregateSemanticIdentityV1::CountDistinct => 1 << 6,
        AggregateSemanticIdentityV1::CountDistinctPresent => 1 << 7,
        AggregateSemanticIdentityV1::Mean => 1 << 8,
        AggregateSemanticIdentityV1::Any => 1 << 9,
        AggregateSemanticIdentityV1::All => 1 << 10,
    }
}

/// Compiler-accepted input shape for one aggregate function.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AggregateInputClassV1 {
    /// The aggregate accepts no field argument.
    NoField,
    /// One required exact `i64`, `u64`, or fixed-decimal field.
    ExactNumericField,
    /// One ordered scalar field, including an optional field's `NoValue` state.
    OrderedScalarField,
    /// One scalar field with canonical typed equality.
    CanonicalScalarField,
    /// One required Boolean field.
    RequiredBooleanField,
}

/// How the aggregate treats the canonical optional `NoValue` state.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AggregateNoValueRuleV1 {
    /// Field values are irrelevant and every admitted row contributes.
    CountsRow,
    /// An optional field is not an accepted input type.
    InvalidInputType,
    /// `NoValue` is a real value under the frozen typed comparator.
    ComparableState,
    /// `NoValue` does not contribute.
    Excluded,
    /// `NoValue` contributes as one canonical distinct value.
    DistinctValue,
}

/// Exact result returned for an empty input population.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AggregateEmptyResultV1 {
    /// Unsigned cardinality zero.
    UnsignedZero,
    /// Exact additive zero at the compiler-resolved input scale.
    ExactNumericZero,
    /// Outer absence, distinct from a contributed `NoValue`.
    Absent,
    /// Exact mean state with zero total and zero count.
    ExactMeanZero,
    /// Boolean false.
    BooleanFalse,
    /// Boolean true.
    BooleanTrue,
}

/// Compiler-resolved public result schema family.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AggregateResultSchemaV1 {
    /// Exact unsigned 64-bit cardinality.
    U64,
    /// Widened exact decimal retaining the input's fixed scale.
    ExactDecimalAtInputScale,
    /// Optional copy of the compiler-resolved input scalar type.
    OptionalInputScalar,
    /// Exact `ExactMeanV1 { total, count }` record.
    ExactMeanV1,
    /// Required Boolean scalar.
    Bool,
    /// Bounded list of the compiler-resolved non-optional input scalar type.
    BoundedInputScalarList,
}

/// Mergeable partial-state family admitted by an exact provider.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AggregatePartialStateV1 {
    /// Checked unsigned 64-bit counter.
    CheckedU64,
    /// Checked signed 128-bit coefficient plus compiler-resolved scale.
    CheckedI128AtInputScale,
    /// Optional scalar selected using the frozen typed comparator.
    OptionalOrderedScalar,
    /// Bounded canonical typed value set.
    BoundedCanonicalSet,
    /// Checked exact total and unsigned count.
    ExactMeanV1,
    /// Boolean disjunction state.
    BooleanAny,
    /// Boolean conjunction state.
    BooleanAll,
}

/// Arithmetic or comparison rule used by the exact evaluator.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AggregateArithmeticV1 {
    /// Checked unsigned 64-bit addition; overflow refuses the whole result.
    CheckedU64,
    /// Checked signed 128-bit addition; overflow refuses the whole result.
    CheckedI128,
    /// The input field's canonical frozen typed comparator.
    FrozenTypedComparator,
    /// Canonical typed equality with checked bounded-set growth.
    CanonicalDistinctSet,
    /// Checked exact total and checked unsigned count.
    CheckedExactMean,
    /// Boolean disjunction.
    BooleanOr,
    /// Boolean conjunction.
    BooleanAnd,
}

/// Static execution-family eligibility for one aggregate semantic.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct AggregateEligibilityV1 {
    ordinary_bounded_fold: bool,
    grouped_bounded_fold: bool,
    whole_result_provider: bool,
}

impl AggregateEligibilityV1 {
    /// Whether the function may fold an earlier compiler-bounded collection.
    #[must_use]
    pub const fn ordinary_bounded_fold(self) -> bool {
        self.ordinary_bounded_fold
    }

    /// Whether the function may fold compiler-bounded groups.
    #[must_use]
    pub const fn grouped_bounded_fold(self) -> bool {
        self.grouped_bounded_fold
    }

    /// Whether an exact whole-result provider may advertise the function.
    #[must_use]
    pub const fn whole_result_provider(self) -> bool {
        self.whole_result_provider
    }
}

/// Where the maximum for one aggregate resource dimension is frozen.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AggregateBudgetBoundV1 {
    /// The function does not retain or consume this resource dimension.
    NotApplicable,
    /// The compiler seals a finite maximum into the complete plan.
    CompilerPlan,
    /// The compiler seals a finite maximum when the aggregate is grouped.
    CompilerPlanWhenGrouped,
}

/// Budget dimensions which every plan using an aggregate must account for.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct AggregateBudgetDimensionsV1 {
    input_rows: AggregateBudgetBoundV1,
    distinct_values: AggregateBudgetBoundV1,
    groups: AggregateBudgetBoundV1,
    state_bytes: AggregateBudgetBoundV1,
    output_bytes: AggregateBudgetBoundV1,
    diagnostic_work: AggregateBudgetBoundV1,
}

impl AggregateBudgetDimensionsV1 {
    /// Whether admitted input rows require a compiler/runtime charge.
    #[must_use]
    pub const fn charges_input_rows(self) -> bool {
        !matches!(self.input_rows, AggregateBudgetBoundV1::NotApplicable)
    }

    /// Source of the maximum admitted input-row count.
    #[must_use]
    pub const fn input_rows(self) -> AggregateBudgetBoundV1 {
        self.input_rows
    }

    /// Source of the maximum retained distinct-value count.
    #[must_use]
    pub const fn distinct_values(self) -> AggregateBudgetBoundV1 {
        self.distinct_values
    }

    /// Whether group cardinality requires an independent bound when grouped.
    #[must_use]
    pub const fn charges_groups(self) -> bool {
        !matches!(self.groups, AggregateBudgetBoundV1::NotApplicable)
    }

    /// Source of the maximum group count.
    #[must_use]
    pub const fn groups(self) -> AggregateBudgetBoundV1 {
        self.groups
    }

    /// Whether partial aggregate state bytes require an independent bound.
    #[must_use]
    pub const fn charges_state_bytes(self) -> bool {
        !matches!(self.state_bytes, AggregateBudgetBoundV1::NotApplicable)
    }

    /// Source of the maximum partial-state bytes.
    #[must_use]
    pub const fn state_bytes(self) -> AggregateBudgetBoundV1 {
        self.state_bytes
    }

    /// Whether encoded aggregate output bytes require an independent bound.
    #[must_use]
    pub const fn charges_output_bytes(self) -> bool {
        !matches!(self.output_bytes, AggregateBudgetBoundV1::NotApplicable)
    }

    /// Source of the maximum encoded output bytes.
    #[must_use]
    pub const fn output_bytes(self) -> AggregateBudgetBoundV1 {
        self.output_bytes
    }

    /// Whether bounded diagnostic work must be accounted for.
    #[must_use]
    pub const fn charges_diagnostic_work(self) -> bool {
        !matches!(self.diagnostic_work, AggregateBudgetBoundV1::NotApplicable)
    }

    /// Source of the maximum bounded diagnostic work.
    #[must_use]
    pub const fn diagnostic_work(self) -> AggregateBudgetBoundV1 {
        self.diagnostic_work
    }
}

/// Policy and inference posture shared by every existing exact aggregate.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct AggregatePolicyV1 {
    admits_rows_before_aggregation: bool,
    partition_scoped_primary: bool,
    withholds_partial_results: bool,
}

impl AggregatePolicyV1 {
    /// Whether row policy is applied before any fold, count, group, or limit.
    #[must_use]
    pub const fn admits_rows_before_aggregation(self) -> bool {
        self.admits_rows_before_aggregation
    }

    /// Whether policy-aligned provider partitioning is the primary mode.
    #[must_use]
    pub const fn partition_scoped_primary(self) -> bool {
        self.partition_scoped_primary
    }

    /// Whether refusal or budget exhaustion releases no partial aggregate.
    #[must_use]
    pub const fn withholds_partial_results(self) -> bool {
        self.withholds_partial_results
    }
}

/// Complete transient semantic descriptor for one exact aggregate function.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct AggregateSemanticDescriptorV1 {
    identity: AggregateSemanticIdentityV1,
    source_spelling: &'static str,
    input_class: AggregateInputClassV1,
    no_value_rule: AggregateNoValueRuleV1,
    empty_result: AggregateEmptyResultV1,
    result_schema: AggregateResultSchemaV1,
    partial_state: AggregatePartialStateV1,
    arithmetic: AggregateArithmeticV1,
    operational_ir_tag: Option<u8>,
    eligibility: AggregateEligibilityV1,
    budgets: AggregateBudgetDimensionsV1,
    policy: AggregatePolicyV1,
}

impl AggregateSemanticDescriptorV1 {
    /// Stable semantic identity.
    #[must_use]
    pub const fn identity(self) -> AggregateSemanticIdentityV1 {
        self.identity
    }

    /// Exact RiffQL source spelling.
    #[must_use]
    pub const fn source_spelling(self) -> &'static str {
        self.source_spelling
    }

    /// Compiler-accepted input class and arity.
    #[must_use]
    pub const fn input_class(self) -> AggregateInputClassV1 {
        self.input_class
    }

    /// Canonical `NoValue` rule.
    #[must_use]
    pub const fn no_value_rule(self) -> AggregateNoValueRuleV1 {
        self.no_value_rule
    }

    /// Empty-population result.
    #[must_use]
    pub const fn empty_result(self) -> AggregateEmptyResultV1 {
        self.empty_result
    }

    /// Compiler-resolved public result schema family.
    #[must_use]
    pub const fn result_schema(self) -> AggregateResultSchemaV1 {
        self.result_schema
    }

    /// Mergeable exact partial-state family.
    #[must_use]
    pub const fn partial_state(self) -> AggregatePartialStateV1 {
        self.partial_state
    }

    /// Exact arithmetic or comparison rule.
    #[must_use]
    pub const fn arithmetic(self) -> AggregateArithmeticV1 {
        self.arithmetic
    }

    /// Existing durable operational query-IR tag, when this semantic is
    /// carried by that format. These values are inventory only and unchanged.
    #[must_use]
    pub const fn operational_ir_tag(self) -> Option<u8> {
        self.operational_ir_tag
    }

    /// Static execution-family eligibility.
    #[must_use]
    pub const fn eligibility(self) -> AggregateEligibilityV1 {
        self.eligibility
    }

    /// Required independent budget dimensions.
    #[must_use]
    pub const fn budgets(self) -> AggregateBudgetDimensionsV1 {
        self.budgets
    }

    /// Policy and inference posture.
    #[must_use]
    pub const fn policy(self) -> AggregatePolicyV1 {
        self.policy
    }
}

const BOUNDED_AND_PROVIDER: AggregateEligibilityV1 = AggregateEligibilityV1 {
    ordinary_bounded_fold: true,
    grouped_bounded_fold: true,
    whole_result_provider: true,
};

const WHOLE_RESULT_ONLY: AggregateEligibilityV1 = AggregateEligibilityV1 {
    ordinary_bounded_fold: false,
    grouped_bounded_fold: false,
    whole_result_provider: true,
};

const EXACT_BUDGETS: AggregateBudgetDimensionsV1 = AggregateBudgetDimensionsV1 {
    input_rows: AggregateBudgetBoundV1::CompilerPlan,
    distinct_values: AggregateBudgetBoundV1::NotApplicable,
    groups: AggregateBudgetBoundV1::CompilerPlanWhenGrouped,
    state_bytes: AggregateBudgetBoundV1::CompilerPlan,
    output_bytes: AggregateBudgetBoundV1::CompilerPlan,
    diagnostic_work: AggregateBudgetBoundV1::CompilerPlan,
};

const EXACT_COUNT_BUDGETS: AggregateBudgetDimensionsV1 = AggregateBudgetDimensionsV1 {
    input_rows: AggregateBudgetBoundV1::CompilerPlan,
    distinct_values: AggregateBudgetBoundV1::NotApplicable,
    groups: AggregateBudgetBoundV1::NotApplicable,
    state_bytes: AggregateBudgetBoundV1::CompilerPlan,
    output_bytes: AggregateBudgetBoundV1::CompilerPlan,
    diagnostic_work: AggregateBudgetBoundV1::CompilerPlan,
};

const EXACT_DISTINCT_BUDGETS: AggregateBudgetDimensionsV1 = AggregateBudgetDimensionsV1 {
    input_rows: AggregateBudgetBoundV1::CompilerPlan,
    distinct_values: AggregateBudgetBoundV1::CompilerPlan,
    groups: AggregateBudgetBoundV1::CompilerPlanWhenGrouped,
    state_bytes: AggregateBudgetBoundV1::CompilerPlan,
    output_bytes: AggregateBudgetBoundV1::CompilerPlan,
    diagnostic_work: AggregateBudgetBoundV1::CompilerPlan,
};

const EXACT_POLICY: AggregatePolicyV1 = AggregatePolicyV1 {
    admits_rows_before_aggregation: true,
    partition_scoped_primary: true,
    withholds_partial_results: true,
};

const AGGREGATE_SEMANTIC_REGISTRY_V1: [AggregateSemanticDescriptorV1; 11] = [
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Count,
        source_spelling: "count",
        input_class: AggregateInputClassV1::NoField,
        no_value_rule: AggregateNoValueRuleV1::CountsRow,
        empty_result: AggregateEmptyResultV1::UnsignedZero,
        result_schema: AggregateResultSchemaV1::U64,
        partial_state: AggregatePartialStateV1::CheckedU64,
        arithmetic: AggregateArithmeticV1::CheckedU64,
        operational_ir_tag: Some(1),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::ExactCount,
        source_spelling: "exact_count",
        input_class: AggregateInputClassV1::NoField,
        no_value_rule: AggregateNoValueRuleV1::CountsRow,
        empty_result: AggregateEmptyResultV1::UnsignedZero,
        result_schema: AggregateResultSchemaV1::U64,
        partial_state: AggregatePartialStateV1::CheckedU64,
        arithmetic: AggregateArithmeticV1::CheckedU64,
        operational_ir_tag: None,
        eligibility: WHOLE_RESULT_ONLY,
        budgets: EXACT_COUNT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Sum,
        source_spelling: "sum",
        input_class: AggregateInputClassV1::ExactNumericField,
        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
        empty_result: AggregateEmptyResultV1::ExactNumericZero,
        result_schema: AggregateResultSchemaV1::ExactDecimalAtInputScale,
        partial_state: AggregatePartialStateV1::CheckedI128AtInputScale,
        arithmetic: AggregateArithmeticV1::CheckedI128,
        operational_ir_tag: Some(2),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Min,
        source_spelling: "min",
        input_class: AggregateInputClassV1::OrderedScalarField,
        no_value_rule: AggregateNoValueRuleV1::ComparableState,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(3),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Max,
        source_spelling: "max",
        input_class: AggregateInputClassV1::OrderedScalarField,
        no_value_rule: AggregateNoValueRuleV1::ComparableState,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(4),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::CountPresent,
        source_spelling: "count_present",
        input_class: AggregateInputClassV1::CanonicalScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::UnsignedZero,
        result_schema: AggregateResultSchemaV1::U64,
        partial_state: AggregatePartialStateV1::CheckedU64,
        arithmetic: AggregateArithmeticV1::CheckedU64,
        operational_ir_tag: Some(5),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::CountDistinct,
        source_spelling: "count_distinct",
        input_class: AggregateInputClassV1::CanonicalScalarField,
        no_value_rule: AggregateNoValueRuleV1::DistinctValue,
        empty_result: AggregateEmptyResultV1::UnsignedZero,
        result_schema: AggregateResultSchemaV1::U64,
        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
        operational_ir_tag: Some(6),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_DISTINCT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::CountDistinctPresent,
        source_spelling: "count_distinct_present",
        input_class: AggregateInputClassV1::CanonicalScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::UnsignedZero,
        result_schema: AggregateResultSchemaV1::U64,
        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
        operational_ir_tag: Some(7),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_DISTINCT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Mean,
        source_spelling: "mean",
        input_class: AggregateInputClassV1::ExactNumericField,
        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
        empty_result: AggregateEmptyResultV1::ExactMeanZero,
        result_schema: AggregateResultSchemaV1::ExactMeanV1,
        partial_state: AggregatePartialStateV1::ExactMeanV1,
        arithmetic: AggregateArithmeticV1::CheckedExactMean,
        operational_ir_tag: Some(8),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Any,
        source_spelling: "any",
        input_class: AggregateInputClassV1::RequiredBooleanField,
        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
        empty_result: AggregateEmptyResultV1::BooleanFalse,
        result_schema: AggregateResultSchemaV1::Bool,
        partial_state: AggregatePartialStateV1::BooleanAny,
        arithmetic: AggregateArithmeticV1::BooleanOr,
        operational_ir_tag: Some(9),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::All,
        source_spelling: "all",
        input_class: AggregateInputClassV1::RequiredBooleanField,
        no_value_rule: AggregateNoValueRuleV1::InvalidInputType,
        empty_result: AggregateEmptyResultV1::BooleanTrue,
        result_schema: AggregateResultSchemaV1::Bool,
        partial_state: AggregatePartialStateV1::BooleanAll,
        arithmetic: AggregateArithmeticV1::BooleanAnd,
        operational_ir_tag: Some(10),
        eligibility: BOUNDED_AND_PROVIDER,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
];

const BOUNDED_FOLD_ONLY: AggregateEligibilityV1 = AggregateEligibilityV1 {
    ordinary_bounded_fold: true,
    grouped_bounded_fold: true,
    whole_result_provider: false,
};

const SAAS_OPERATIONAL_AGGREGATE_REGISTRY_V1: [AggregateSemanticDescriptorV1; 9] = [
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Min,
        source_spelling: "median",
        input_class: AggregateInputClassV1::OrderedScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(11),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Min,
        source_spelling: "p90",
        input_class: AggregateInputClassV1::OrderedScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(12),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Min,
        source_spelling: "p95",
        input_class: AggregateInputClassV1::OrderedScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(13),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Min,
        source_spelling: "p99",
        input_class: AggregateInputClassV1::OrderedScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(14),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Min,
        source_spelling: "first",
        input_class: AggregateInputClassV1::CanonicalScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(15),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Max,
        source_spelling: "last",
        input_class: AggregateInputClassV1::CanonicalScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::Absent,
        result_schema: AggregateResultSchemaV1::OptionalInputScalar,
        partial_state: AggregatePartialStateV1::OptionalOrderedScalar,
        arithmetic: AggregateArithmeticV1::FrozenTypedComparator,
        operational_ir_tag: Some(16),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::Sum,
        source_spelling: "stddev",
        input_class: AggregateInputClassV1::ExactNumericField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::ExactNumericZero,
        result_schema: AggregateResultSchemaV1::ExactDecimalAtInputScale,
        partial_state: AggregatePartialStateV1::CheckedI128AtInputScale,
        arithmetic: AggregateArithmeticV1::CheckedI128,
        operational_ir_tag: Some(17),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::CountPresent,
        source_spelling: "collect",
        input_class: AggregateInputClassV1::CanonicalScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::UnsignedZero,
        result_schema: AggregateResultSchemaV1::BoundedInputScalarList,
        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
        operational_ir_tag: Some(18),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_DISTINCT_BUDGETS,
        policy: EXACT_POLICY,
    },
    AggregateSemanticDescriptorV1 {
        identity: AggregateSemanticIdentityV1::CountDistinctPresent,
        source_spelling: "collect_distinct",
        input_class: AggregateInputClassV1::CanonicalScalarField,
        no_value_rule: AggregateNoValueRuleV1::Excluded,
        empty_result: AggregateEmptyResultV1::UnsignedZero,
        result_schema: AggregateResultSchemaV1::BoundedInputScalarList,
        partial_state: AggregatePartialStateV1::BoundedCanonicalSet,
        arithmetic: AggregateArithmeticV1::CanonicalDistinctSet,
        operational_ir_tag: Some(19),
        eligibility: BOUNDED_FOLD_ONLY,
        budgets: EXACT_DISTINCT_BUDGETS,
        policy: EXACT_POLICY,
    },
];

/// Returns the closed v1 aggregate semantic registry in stable identity order.
#[must_use]
pub const fn aggregate_semantic_registry_v1() -> &'static [AggregateSemanticDescriptorV1] {
    &AGGREGATE_SEMANTIC_REGISTRY_V1
}