20
20
*/
21
21
@ ExperimentalApi
22
22
public enum MetricStat {
23
- VALUE_COUNT ("value_count" ),
24
- SUM ("sum" ),
25
- MIN ("min" ),
26
- MAX ("max" ),
27
- AVG ("avg" , VALUE_COUNT , SUM ),
28
- DOC_COUNT ("doc_count" , true );
23
+ VALUE_COUNT ("value_count" , 0 ),
24
+ SUM ("sum" , 1 ),
25
+ MIN ("min" , 2 ),
26
+ MAX ("max" , 3 ),
27
+ AVG ("avg" , 4 , VALUE_COUNT , SUM ),
28
+ DOC_COUNT ("doc_count" , true , 5 );
29
29
30
30
private final String typeName ;
31
31
private final MetricStat [] baseMetrics ;
32
+ private final int metricOrdinal ;
32
33
33
34
// System field stats cannot be used as input for user metric types
34
35
private final boolean isSystemFieldStat ;
35
36
36
- MetricStat (String typeName ) {
37
- this (typeName , false );
37
+ MetricStat (String typeName , int metricOrdinal ) {
38
+ this (typeName , false , metricOrdinal );
38
39
}
39
40
40
- MetricStat (String typeName , MetricStat ... baseMetrics ) {
41
- this (typeName , false , baseMetrics );
41
+ MetricStat (String typeName , int metricOrdinal , MetricStat ... baseMetrics ) {
42
+ this (typeName , false , metricOrdinal , baseMetrics );
42
43
}
43
44
44
- MetricStat (String typeName , boolean isSystemFieldStat , MetricStat ... baseMetrics ) {
45
+ MetricStat (String typeName , boolean isSystemFieldStat , int metricOrdinal , MetricStat ... baseMetrics ) {
45
46
this .typeName = typeName ;
46
47
this .isSystemFieldStat = isSystemFieldStat ;
47
48
this .baseMetrics = baseMetrics ;
49
+ this .metricOrdinal = metricOrdinal ;
48
50
}
49
51
50
52
public String getTypeName () {
51
53
return typeName ;
52
54
}
53
55
56
+ public int getMetricOrdinal () {
57
+ return metricOrdinal ;
58
+ }
59
+
54
60
/**
55
61
* Return the list of metrics that this metric is derived from
56
62
* For example, AVG is derived from COUNT and SUM
@@ -76,4 +82,13 @@ public static MetricStat fromTypeName(String typeName) {
76
82
}
77
83
throw new IllegalArgumentException ("Invalid metric stat: " + typeName );
78
84
}
85
+
86
+ public static MetricStat fromMetricOrdinal (int metricOrdinal ) {
87
+ for (MetricStat metric : MetricStat .values ()) {
88
+ if (metric .getMetricOrdinal () == metricOrdinal ) {
89
+ return metric ;
90
+ }
91
+ }
92
+ throw new IllegalArgumentException ("Invalid metric stat: " + metricOrdinal );
93
+ }
79
94
}
0 commit comments