Skip to content

Commit bd8d67d

Browse files
committed
add label to metric enum
1 parent d9e6422 commit bd8d67d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/AggregateMetricDoubleBlockBuilder.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,26 @@ public BlockLoader.IntBuilder count() {
139139
}
140140

141141
public enum Metric {
142-
MIN(0),
143-
MAX(1),
144-
SUM(2),
145-
COUNT(3);
142+
MIN(0, "min"),
143+
MAX(1, "max"),
144+
SUM(2, "sum"),
145+
COUNT(3, "value_count");
146146

147147
private final int index;
148+
private final String label;
148149

149-
Metric(int index) {
150+
Metric(int index, String label) {
150151
this.index = index;
152+
this.label = label;
151153
}
152154

153155
public int getIndex() {
154156
return index;
155157
}
158+
159+
public String getLabel() {
160+
return label;
161+
}
156162
}
157163

158164
public record AggregateMetricDoubleLiteral(Double min, Double max, Double sum, Integer count) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/type/EsqlDataTypeConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,12 @@ public static String aggregateMetricDoubleBlockToString(CompositeBlock composite
679679
for (Metric metric : List.of(Metric.MIN, Metric.MAX, Metric.SUM)) {
680680
var block = compositeBlock.getBlock(metric.getIndex());
681681
if (block.isNull(index) == false) {
682-
builder.field(metric.name().toLowerCase(), ((DoubleBlock) block).getDouble(index));
682+
builder.field(metric.getLabel(), ((DoubleBlock) block).getDouble(index));
683683
}
684684
}
685-
var countBlock = compositeBlock.getBlock(AggregateMetricDoubleBlockBuilder.Metric.COUNT.getIndex());
685+
var countBlock = compositeBlock.getBlock(Metric.COUNT.getIndex());
686686
if (countBlock.isNull(index) == false) {
687-
builder.field("value_count", ((IntBlock) countBlock).getInt(index));
687+
builder.field(Metric.COUNT.getLabel(), ((IntBlock) countBlock).getInt(index));
688688
}
689689
builder.endObject();
690690
return Strings.toString(builder);

0 commit comments

Comments
 (0)