@@ -6,31 +6,35 @@ use promql_utilities::query_logics::enums::Statistic;
66use tracing:: { debug, warn} ;
77
88use crate :: aggregation_config:: { AggregationConfig , AggregationIdInfo } ;
9+ use crate :: enums:: WindowType ;
910use crate :: query_requirements:: QueryRequirements ;
1011use crate :: utils:: normalize_spatial_filter;
12+ use promql_utilities:: query_logics:: enums:: AggregationType ;
1113
1214// ---------------------------------------------------------------------------
1315// Pure compatibility helpers
1416// ---------------------------------------------------------------------------
1517
16- /// Returns the aggregation_type strings that can serve this statistic.
17- pub fn compatible_agg_types ( stat : Statistic ) -> & ' static [ & ' static str ] {
18+ /// Returns the aggregation types that can serve this statistic.
19+ pub fn compatible_agg_types ( stat : Statistic ) -> & ' static [ AggregationType ] {
1820 match stat {
19- Statistic :: Sum => & [ " Sum" , "MultipleSumAccumulator" ] ,
21+ Statistic :: Sum => & [ AggregationType :: Sum , AggregationType :: MultipleSum ] ,
2022 Statistic :: Count => & [
21- "CountMinSketch" ,
22- "CountMinSketchWithHeap" ,
23- "CountMinSketchWithHeapAccumulator" ,
23+ AggregationType :: CountMinSketch ,
24+ AggregationType :: CountMinSketchWithHeap ,
2425 ] ,
25- Statistic :: Min => & [ "MinMax" , "MultipleMinMaxAccumulator" ] ,
26- Statistic :: Max => & [ "MinMax" , "MultipleMinMaxAccumulator" ] ,
27- Statistic :: Quantile => & [ "DatasketchesKLL" , "HydraKLL" ] ,
28- Statistic :: Rate | Statistic :: Increase => & [ "Increase" , "MultipleIncreaseAccumulator" ] ,
29- Statistic :: Cardinality => & [ "SetAggregator" , "DeltaSetAggregator" ] ,
30- Statistic :: Topk => & [
31- "CountMinSketchWithHeap" ,
32- "CountMinSketchWithHeapAccumulator" ,
26+ Statistic :: Min | Statistic :: Max => {
27+ & [ AggregationType :: MinMax , AggregationType :: MultipleMinMax ]
28+ }
29+ Statistic :: Quantile => & [ AggregationType :: DatasketchesKLL , AggregationType :: HydraKLL ] ,
30+ Statistic :: Rate | Statistic :: Increase => {
31+ & [ AggregationType :: Increase , AggregationType :: MultipleIncrease ]
32+ }
33+ Statistic :: Cardinality => & [
34+ AggregationType :: SetAggregator ,
35+ AggregationType :: DeltaSetAggregator ,
3336 ] ,
37+ Statistic :: Topk => & [ AggregationType :: CountMinSketchWithHeap ] ,
3438 }
3539}
3640
@@ -46,20 +50,13 @@ pub fn required_sub_type(stat: Statistic) -> Option<&'static str> {
4650
4751/// Whether this value aggregation type requires a paired key aggregation
4852/// (`SetAggregator` or `DeltaSetAggregator`).
49- pub fn is_multi_population_value_type ( agg_type : & str ) -> bool {
50- matches ! (
51- agg_type,
52- "MultipleSumAccumulator"
53- | "MultipleMinMaxAccumulator"
54- | "MultipleIncreaseAccumulator"
55- | "CountMinSketchWithHeap"
56- | "CountMinSketchWithHeapAccumulator"
57- )
53+ pub fn is_multi_population_value_type ( agg_type : AggregationType ) -> bool {
54+ agg_type. is_multi_population_value_type ( )
5855}
5956
6057/// Whether this type is a key aggregation (tracks which label-value combinations exist).
61- fn is_key_agg_type ( agg_type : & str ) -> bool {
62- matches ! ( agg_type, "SetAggregator" | "DeltaSetAggregator" )
58+ fn is_key_agg_type ( agg_type : AggregationType ) -> bool {
59+ agg_type. is_key_agg_type ( )
6360}
6461
6562/// Window compatibility: can `config` serve a query needing `data_range_ms`?
@@ -76,9 +73,9 @@ pub fn window_compatible(config: &AggregationConfig, data_range_ms: Option<u64>)
7673 if window_ms == 0 || range == 0 {
7774 return false ;
7875 }
79- match config. window_type . as_str ( ) {
80- "sliding" => range == window_ms,
81- _ => range % window_ms == 0 , // tumbling (or unknown — treat as tumbling)
76+ match config. window_type {
77+ WindowType :: Sliding => range == window_ms,
78+ WindowType :: Tumbling => range % window_ms == 0 ,
8279 }
8380}
8481
@@ -152,7 +149,7 @@ pub fn find_compatible_aggregation(
152149 . values ( )
153150 . filter ( |c| {
154151 let ok = c. metric == requirements. metric
155- && types. contains ( & c. aggregation_type . as_str ( ) )
152+ && types. contains ( & c. aggregation_type )
156153 && sub_type. is_none_or ( |st| c. aggregation_sub_type == st)
157154 && window_compatible ( c, requirements. data_range_ms )
158155 && labels_compatible ( & c. grouping_labels , & requirements. grouping_labels )
@@ -218,11 +215,11 @@ pub fn find_compatible_aggregation(
218215 }
219216
220217 // If value type is multi-population, find the paired key aggregation.
221- let key_agg: & AggregationConfig = if is_multi_population_value_type ( & value_agg. aggregation_type )
218+ let key_agg: & AggregationConfig = if is_multi_population_value_type ( value_agg. aggregation_type )
222219 {
223220 let ka = configs
224221 . values ( )
225- . find ( |c| c. metric == requirements. metric && is_key_agg_type ( & c. aggregation_type ) ) ;
222+ . find ( |c| c. metric == requirements. metric && is_key_agg_type ( c. aggregation_type ) ) ;
226223 if ka. is_none ( ) {
227224 warn ! (
228225 metric = %requirements. metric,
@@ -246,9 +243,9 @@ pub fn find_compatible_aggregation(
246243
247244 Some ( AggregationIdInfo {
248245 aggregation_id_for_value : value_agg. aggregation_id ,
249- aggregation_type_for_value : value_agg. aggregation_type . clone ( ) ,
246+ aggregation_type_for_value : value_agg. aggregation_type ,
250247 aggregation_id_for_key : key_agg. aggregation_id ,
251- aggregation_type_for_key : key_agg. aggregation_type . clone ( ) ,
248+ aggregation_type_for_key : key_agg. aggregation_type ,
252249 } )
253250}
254251
@@ -279,7 +276,7 @@ mod tests {
279276 let spatial_filter_normalized = normalize_spatial_filter ( spatial_filter) ;
280277 AggregationConfig {
281278 aggregation_id : id,
282- aggregation_type : agg_type. to_string ( ) ,
279+ aggregation_type : agg_type. parse :: < AggregationType > ( ) . expect ( "valid agg type" ) ,
283280 aggregation_sub_type : sub_type. to_string ( ) ,
284281 parameters : HashMap :: new ( ) ,
285282 grouping_labels,
@@ -288,7 +285,7 @@ mod tests {
288285 original_yaml : String :: new ( ) ,
289286 window_size : window_size_s,
290287 slide_interval : window_size_s,
291- window_type : window_type. to_string ( ) ,
288+ window_type : window_type. parse :: < WindowType > ( ) . unwrap_or_default ( ) ,
292289 spatial_filter : spatial_filter. to_string ( ) ,
293290 spatial_filter_normalized,
294291 metric : metric. to_string ( ) ,
0 commit comments