Skip to content

Commit

Permalink
fix: ordering terms aggregation on top metrics null values (#85774)
Browse files Browse the repository at this point in the history
If top metrics buckets are never collected (i.e. a filter never
passing data to a top metrics aggregator) ordering results in an
index out of bounds exception. THis is because the data array
expected to include data is actually empty.

Here we use the special Double.NaN value to report missing data
to sort on for the top metrics metric field. This results in the
comparator ordering data using another comparator (the default
'_key' comprator).
  • Loading branch information
salvatore-campagna authored Apr 19, 2022
1 parent 33a553f commit 3b78a4c
Show file tree
Hide file tree
Showing 3 changed files with 777 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/85774.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 85774
summary: "Fix: ordering terms aggregation on top metrics null values"
area: Aggregations
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ static class DoubleMetricValues extends CollectingMetricValues {

@Override
public double doubleValue(long index) {
if (index < 0 || index >= values.size()) {
return Double.NaN;
}
return values.get(index);
}

Expand Down Expand Up @@ -357,7 +360,7 @@ static class LongMetricValues extends CollectingMetricValues {

@Override
public double doubleValue(long index) {
if (empty.isEmpty(index)) {
if (empty.isEmpty(index) || index < 0 || index >= values.size()) {
return Double.NaN;
}
return values.get(index);
Expand Down
Loading

0 comments on commit 3b78a4c

Please sign in to comment.