Skip to content

Commit

Permalink
Fix sorting on NaN values in aggregations.
Browse files Browse the repository at this point in the history
Closes elastic#5236.
  • Loading branch information
thanodnl authored and jpountz committed Mar 4, 2014
1 parent 0497729 commit c98213e
Showing 1 changed file with 10 additions and 4 deletions.
Expand Up @@ -212,8 +212,11 @@ public int compare(Terms.Bucket o1, Terms.Bucket o2) {
double v2 = ((MetricsAggregator.MultiValue) aggregator).metric(valueName, ((InternalTerms.Bucket) o2).bucketOrd);
// some metrics may return NaN (eg. avg, variance, etc...) in which case we'd like to push all of those to
// the bottom
if (v1 == Double.NaN) {
return asc ? 1 : -1;
if (Double.isNaN(v1)) {
return Double.isNaN(v2) ? 0 : 1;
}
if (Double.isNaN(v2)) {
return -1;
}
return asc ? Double.compare(v1, v2) : Double.compare(v2, v1);
}
Expand All @@ -227,8 +230,11 @@ public int compare(Terms.Bucket o1, Terms.Bucket o2) {
double v2 = ((MetricsAggregator.SingleValue) aggregator).metric(((InternalTerms.Bucket) o2).bucketOrd);
// some metrics may return NaN (eg. avg, variance, etc...) in which case we'd like to push all of those to
// the bottom
if (v1 == Double.NaN) {
return asc ? 1 : -1;
if (Double.isNaN(v1)) {
return Double.isNaN(v2) ? 0 : 1;
}
if (Double.isNaN(v2)) {
return -1;
}
return asc ? Double.compare(v1, v2) : Double.compare(v2, v1);
}
Expand Down

0 comments on commit c98213e

Please sign in to comment.