From 9afaa2b94a2ba444e30af002ed750c843e02666e Mon Sep 17 00:00:00 2001 From: jon-wei Date: Thu, 24 Mar 2016 18:38:42 -0700 Subject: [PATCH] Fix HyperUniquesAggregatorFactory comparator --- .../HyperUniquesAggregatorFactory.java | 16 ++-------------- .../druid/query/topn/TopNQueryRunnerTest.java | 18 +++++++++--------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregatorFactory.java b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregatorFactory.java index cc8ff7ba431..852b4fa323d 100644 --- a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregatorFactory.java +++ b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregatorFactory.java @@ -21,6 +21,7 @@ package io.druid.query.aggregation.hyperloglog; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.collect.Ordering; import com.metamx.common.IAE; import com.metamx.common.StringUtils; import io.druid.query.aggregation.Aggregator; @@ -106,20 +107,7 @@ public class HyperUniquesAggregatorFactory extends AggregatorFactory @Override public Comparator getComparator() { - return new Comparator() - { - @Override - public int compare(HyperLogLogCollector lhs, HyperLogLogCollector rhs) - { - if(lhs == null) { - return -1; - } - if(rhs == null) { - return 1; - } - return lhs.compareTo(rhs); - } - }; + return Ordering.natural().nullsFirst(); } @Override diff --git a/processing/src/test/java/io/druid/query/topn/TopNQueryRunnerTest.java b/processing/src/test/java/io/druid/query/topn/TopNQueryRunnerTest.java index f822c18ec21..4bee2f23aae 100644 --- a/processing/src/test/java/io/druid/query/topn/TopNQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/topn/TopNQueryRunnerTest.java @@ -377,17 +377,17 @@ public class TopNQueryRunnerTest new TopNResultValue( Arrays.>asList( ImmutableMap.builder() - .put("market", "total_market") - .put("uniques", 0) - .build(), + .put("market", "spot") + .put("uniques", 0) + .build(), ImmutableMap.builder() - .put("market", "spot") - .put("uniques", 0) - .build(), + .put("market", "total_market") + .put("uniques", 0) + .build(), ImmutableMap.builder() - .put("market", "upfront") - .put("uniques", 0) - .build() + .put("market", "upfront") + .put("uniques", 0) + .build() ) ) )