From 63a897c278bb46702345b2f08b0b7b400d0bb925 Mon Sep 17 00:00:00 2001 From: Roman Leventov Date: Wed, 7 Jun 2017 11:54:25 -0500 Subject: [PATCH] Enable most IntelliJ 'Probable bugs' inspections (#4353) * Enable most IntelliJ 'Probable bugs' inspections * Fix in RemoteTestNG * Fix IndexSpec's equals() and hashCode() to include longEncoding * Fix inspection errors * Extract global isntance of natural().nullsFirst(); address comments * Fix * Use noinspection comments instead of SuppressWarnings on method for IntelliJ-specific inspections * Prohibit Ordering.natural().nullsFirst() using Checkstyle --- .idea/inspectionProfiles/Druid.xml | 85 +++++++++++++++++++ .../druid/data/input/impl/TimestampSpec.java | 15 +++- codestyle/checkstyle.xml | 19 ++++- .../partition/IntegerPartitionChunk.java | 8 +- .../partition/LinearPartitionChunk.java | 8 +- .../partition/StringPartitionChunk.java | 8 +- .../common/guava/ComplexSequenceTest.java | 15 +--- .../druid/extendedset/intset/ConciseSet.java | 16 +++- .../rocketmq/RocketMQFirehoseFactory.java | 4 +- .../rabbitmq/RabbitMQProducerMain.java | 13 ++- .../histogram/ApproximateHistogram.java | 2 +- .../histogram/QuantilePostAggregator.java | 2 +- .../histogram/QuantilesPostAggregator.java | 2 +- .../histogram/ApproximateHistogramTest.java | 2 + .../namespace/cache/CacheSchedulerTest.java | 2 + .../io/druid/server/lookup/LoadingLookup.java | 9 ++ .../io/druid/server/lookup/PollingLookup.java | 8 ++ .../server/lookup/jdbc/JdbcDataFetcher.java | 10 +++ .../java/io/druid/indexer/BucketTest.java | 4 +- .../indexing/common/task/AppendTask.java | 4 +- .../IngestSegmentFirehoseFactory.java | 4 +- .../src/main/java/org/testng/TestNG.java | 2 +- .../java/org/testng/remote/RemoteTestNG.java | 2 +- .../java/util/common/guava/Comparators.java | 30 +++++++ .../HyperUniquesAggregatorFactory.java | 4 +- .../post/ConstantPostAggregator.java | 10 +-- .../FinalizingFieldAccessPostAggregator.java | 4 +- .../io/druid/query/groupby/GroupByQuery.java | 9 +- .../query/groupby/GroupByQueryConfig.java | 16 ++++ .../query/lookup/LookupExtractionFn.java | 12 +++ .../LookupExtractorFactoryContainer.java | 6 +- .../SegmentMetadataQueryQueryToolChest.java | 12 +-- .../query/ordering/StringComparators.java | 8 +- .../java/io/druid/segment/IndexMerger.java | 25 +++--- .../java/io/druid/segment/IndexMergerV9.java | 8 +- .../main/java/io/druid/segment/IndexSpec.java | 36 ++++---- .../druid/segment/StringDimensionHandler.java | 2 +- .../druid/segment/StringDimensionIndexer.java | 7 +- .../data/BitmapCompressedIndexedInts.java | 4 +- .../CompressedByteBufferObjectStrategy.java | 5 +- .../CompressedFloatBufferObjectStrategy.java | 4 +- .../CompressedIntBufferObjectStrategy.java | 5 +- .../CompressedLongBufferObjectStrategy.java | 4 +- .../io/druid/segment/data/GenericIndexed.java | 5 +- .../data/VSizeCompressedObjectStrategy.java | 4 +- .../filter/ColumnComparisonFilter.java | 2 +- .../DictionaryEncodedColumnPartSerde.java | 6 +- .../query/cache/CacheKeyBuilderTest.java | 8 +- .../ByteBufferMinMaxOffsetHeapTest.java | 14 +-- .../io/druid/segment/SchemalessIndexTest.java | 4 +- .../io/druid/client/DirectDruidClient.java | 9 ++ .../granularity/ArbitraryGranularitySpec.java | 10 +++ .../druid/segment/realtime/FireHydrant.java | 2 +- .../coordinator/CostBalancerStrategy.java | 1 + .../LookupExtractorFactoryMapContainer.java | 6 +- .../client/CachingClusteredClientTest.java | 3 +- 56 files changed, 354 insertions(+), 175 deletions(-) diff --git a/.idea/inspectionProfiles/Druid.xml b/.idea/inspectionProfiles/Druid.xml index c820649923e1..5eb60b4ba691 100644 --- a/.idea/inspectionProfiles/Druid.xml +++ b/.idea/inspectionProfiles/Druid.xml @@ -5,18 +5,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/main/java/io/druid/data/input/impl/TimestampSpec.java b/api/src/main/java/io/druid/data/input/impl/TimestampSpec.java index e956abef6ada..5ebf8504e63c 100644 --- a/api/src/main/java/io/druid/data/input/impl/TimestampSpec.java +++ b/api/src/main/java/io/druid/data/input/impl/TimestampSpec.java @@ -47,12 +47,13 @@ private static class ParseCtx private final String timestampColumn; private final String timestampFormat; - private final Function timestampConverter; // this value should never be set for production data private final DateTime missingValue; + /** This field is a derivative of {@link #timestampFormat}; not checked in {@link #equals} and {@link #hashCode} */ + private final Function timestampConverter; // remember last value parsed - private ParseCtx parseCtx = new ParseCtx(); + private transient ParseCtx parseCtx = new ParseCtx(); @JsonCreator public TimestampSpec( @@ -141,6 +142,16 @@ public int hashCode() return result; } + @Override + public String toString() + { + return "TimestampSpec{" + + "timestampColumn='" + timestampColumn + '\'' + + ", timestampFormat='" + timestampFormat + '\'' + + ", missingValue=" + missingValue + + '}'; + } + //simple merge strategy on timestampSpec that checks if all are equal or else //returns null. this can be improved in future but is good enough for most use-cases. public static TimestampSpec mergeTimestampSpec(List toMerge) { diff --git a/codestyle/checkstyle.xml b/codestyle/checkstyle.xml index 860df828adc7..17570da445dd 100644 --- a/codestyle/checkstyle.xml +++ b/codestyle/checkstyle.xml @@ -29,10 +29,18 @@ + + + + + + + + @@ -44,19 +52,24 @@ - + - + - + + + + + + diff --git a/common/src/main/java/io/druid/timeline/partition/IntegerPartitionChunk.java b/common/src/main/java/io/druid/timeline/partition/IntegerPartitionChunk.java index 8d5e6b7f0f06..102f18bc92c5 100644 --- a/common/src/main/java/io/druid/timeline/partition/IntegerPartitionChunk.java +++ b/common/src/main/java/io/druid/timeline/partition/IntegerPartitionChunk.java @@ -19,16 +19,10 @@ package io.druid.timeline.partition; -import com.google.common.collect.Ordering; - -import java.util.Comparator; - /** */ public class IntegerPartitionChunk implements PartitionChunk { - Comparator comparator = Ordering.natural().nullsFirst(); - private final Integer start; private final Integer end; private final int chunkNumber; @@ -96,7 +90,7 @@ public int compareTo(PartitionChunk chunk) { if (chunk instanceof IntegerPartitionChunk) { IntegerPartitionChunk intChunk = (IntegerPartitionChunk) chunk; - return comparator.compare(chunkNumber, intChunk.chunkNumber); + return Integer.compare(chunkNumber, intChunk.chunkNumber); } else { throw new IllegalArgumentException("Cannot compare against something that is not an IntegerPartitionChunk."); } diff --git a/common/src/main/java/io/druid/timeline/partition/LinearPartitionChunk.java b/common/src/main/java/io/druid/timeline/partition/LinearPartitionChunk.java index b9e529bb36ea..686f1952aa65 100644 --- a/common/src/main/java/io/druid/timeline/partition/LinearPartitionChunk.java +++ b/common/src/main/java/io/druid/timeline/partition/LinearPartitionChunk.java @@ -19,14 +19,8 @@ package io.druid.timeline.partition; -import com.google.common.collect.Ordering; - -import java.util.Comparator; - public class LinearPartitionChunk implements PartitionChunk { - Comparator comparator = Ordering.natural().nullsFirst(); - private final int chunkNumber; private final T object; @@ -81,7 +75,7 @@ public int compareTo(PartitionChunk chunk) if (chunk instanceof LinearPartitionChunk) { LinearPartitionChunk linearChunk = (LinearPartitionChunk) chunk; - return comparator.compare(chunkNumber, linearChunk.chunkNumber); + return Integer.compare(chunkNumber, linearChunk.chunkNumber); } throw new IllegalArgumentException("Cannot compare against something that is not a LinearPartitionChunk."); } diff --git a/common/src/main/java/io/druid/timeline/partition/StringPartitionChunk.java b/common/src/main/java/io/druid/timeline/partition/StringPartitionChunk.java index dfec460e7cff..4d54ac650e8c 100644 --- a/common/src/main/java/io/druid/timeline/partition/StringPartitionChunk.java +++ b/common/src/main/java/io/druid/timeline/partition/StringPartitionChunk.java @@ -19,16 +19,10 @@ package io.druid.timeline.partition; -import com.google.common.collect.Ordering; - -import java.util.Comparator; - /** */ public class StringPartitionChunk implements PartitionChunk { - private static final Comparator comparator = Ordering.natural().nullsFirst(); - private final String start; private final String end; private final int chunkNumber; @@ -95,7 +89,7 @@ public int compareTo(PartitionChunk chunk) if (chunk instanceof StringPartitionChunk) { StringPartitionChunk stringChunk = (StringPartitionChunk) chunk; - return comparator.compare(chunkNumber, stringChunk.chunkNumber); + return Integer.compare(chunkNumber, stringChunk.chunkNumber); } throw new IllegalArgumentException("Cannot compare against something that is not a StringPartitionChunk."); } diff --git a/common/src/test/java/io/druid/common/guava/ComplexSequenceTest.java b/common/src/test/java/io/druid/common/guava/ComplexSequenceTest.java index 0e7db26ffb8e..53ae9fe4e639 100644 --- a/common/src/test/java/io/druid/common/guava/ComplexSequenceTest.java +++ b/common/src/test/java/io/druid/common/guava/ComplexSequenceTest.java @@ -19,15 +19,13 @@ package io.druid.common.guava; -import com.google.common.collect.Ordering; import com.google.common.primitives.Ints; - +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.guava.Sequence; import io.druid.java.util.common.guava.Sequences; import io.druid.java.util.common.guava.Yielder; import io.druid.java.util.common.guava.YieldingAccumulator; import io.druid.java.util.common.guava.nary.BinaryFn; - import org.junit.Assert; import org.junit.Test; @@ -82,7 +80,7 @@ private Sequence simple(int... values) private Sequence combine(Sequence sequence) { - return CombiningSequence.create(sequence, alwaysSame, plus); + return CombiningSequence.create(sequence, Comparators.alwaysEqual(), plus); } private Sequence concat(Sequence... sequences) @@ -90,15 +88,6 @@ private Sequence concat(Sequence... sequences) return Sequences.concat(Arrays.asList(sequences)); } - private final Ordering alwaysSame = new Ordering() - { - @Override - public int compare(Integer left, Integer right) - { - return 0; - } - }; - private final BinaryFn plus = new BinaryFn() { @Override diff --git a/extendedset/src/main/java/io/druid/extendedset/intset/ConciseSet.java b/extendedset/src/main/java/io/druid/extendedset/intset/ConciseSet.java index c96e01540f3b..40fa797dde30 100755 --- a/extendedset/src/main/java/io/druid/extendedset/intset/ConciseSet.java +++ b/extendedset/src/main/java/io/druid/extendedset/intset/ConciseSet.java @@ -468,7 +468,7 @@ private void compact() * string. The bit must be appendable, that is it must represent an * integer that is strictly greater than the maximum integer in the set. * Note that the parameter range check is performed by the public method - * {@link #add(Integer)} and not in this method. + * {@link #add)} and not in this method. *

* NOTE: This method assumes that the last element of {@link #words} * (i.e. getLastWord()) must be one of the @@ -712,6 +712,7 @@ private ConciseSet performOperation(ConciseSet other, Operator operator) if (!otherItr.isLiteral) { int minCount = Math.min(thisItr.count, otherItr.count); res.appendFill(minCount, operator.combineLiterals(thisItr.word, otherItr.word)); + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext(minCount) | !otherItr.prepareNext(minCount)) // NOT || { break; @@ -719,6 +720,7 @@ private ConciseSet performOperation(ConciseSet other, Operator operator) } else { res.appendLiteral(operator.combineLiterals(thisItr.toLiteral(), otherItr.word)); thisItr.word--; + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext(1) | !otherItr.prepareNext()) // do NOT use "||" { break; @@ -727,12 +729,14 @@ private ConciseSet performOperation(ConciseSet other, Operator operator) } else if (!otherItr.isLiteral) { res.appendLiteral(operator.combineLiterals(thisItr.word, otherItr.toLiteral())); otherItr.word--; + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext() | !otherItr.prepareNext(1)) // do NOT use "||" { break; } } else { res.appendLiteral(operator.combineLiterals(thisItr.word, otherItr.word)); + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext() | !otherItr.prepareNext()) // do NOT use "||" { break; @@ -791,6 +795,7 @@ private ConciseSet performOperation(ConciseSet other, Operator operator) /** * {@inheritDoc} */ + @SuppressWarnings("NonShortCircuitBooleanExpression") @Override public int intersectionSize(IntSet o) { @@ -1715,6 +1720,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l if ((ConciseSetUtils.SEQUENCE_BIT & thisItr.word & otherItr.word) != 0) { return true; } + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext(minCount) | !otherItr.prepareNext(minCount)) // NOT || { return false; @@ -1724,6 +1730,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l return true; } thisItr.word--; + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext(1) | !otherItr.prepareNext()) // do NOT use "||" { return false; @@ -1734,6 +1741,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l return true; } otherItr.word--; + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext() | !otherItr.prepareNext(1)) // do NOT use "||" { return false; @@ -1742,6 +1750,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l if ((thisItr.word & otherItr.word) != ConciseSetUtils.ALL_ZEROS_LITERAL) { return true; } + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext() | !otherItr.prepareNext()) // do NOT use "||" { return false; @@ -1804,6 +1813,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l return true; } } + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext(minCount) | !otherItr.prepareNext(minCount)) // NOT || { return false; @@ -1814,6 +1824,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l return true; } thisItr.word--; + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext(1) | !otherItr.prepareNext()) // do NOT use "||" { return false; @@ -1825,6 +1836,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l return true; } otherItr.word--; + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext() | !otherItr.prepareNext(1)) // do NOT use "||" { return false; @@ -1834,6 +1846,7 @@ && maxLiteralLengthMultiplication(getSequenceCount(other.words[0]) + 1) > this.l if (res >= minElements) { return true; } + //noinspection NonShortCircuitBooleanExpression if (!thisItr.prepareNext() | !otherItr.prepareNext()) // do NOT use "||" { return false; @@ -2011,6 +2024,7 @@ public boolean equals(Object obj) /** * {@inheritDoc} */ + @SuppressWarnings("CompareToUsesNonFinalVariable") @Override public int compareTo(IntSet o) { diff --git a/extensions-contrib/druid-rocketmq/src/main/java/io/druid/firehose/rocketmq/RocketMQFirehoseFactory.java b/extensions-contrib/druid-rocketmq/src/main/java/io/druid/firehose/rocketmq/RocketMQFirehoseFactory.java index 1bd78f8a3027..7ef256339d8e 100644 --- a/extensions-contrib/druid-rocketmq/src/main/java/io/druid/firehose/rocketmq/RocketMQFirehoseFactory.java +++ b/extensions-contrib/druid-rocketmq/src/main/java/io/druid/firehose/rocketmq/RocketMQFirehoseFactory.java @@ -276,7 +276,7 @@ public void run() OffsetStore offsetStore = defaultMQPullConsumer.getOffsetStore(); Set updated = new HashSet<>(); // calculate offsets according to consuming windows. - for (ConcurrentHashMap.Entry> entry : windows.entrySet()) { + for (Map.Entry> entry : windows.entrySet()) { while (!entry.getValue().isEmpty()) { long offset = offsetStore.readOffset(entry.getKey(), ReadOffsetType.MEMORY_FIRST_THEN_STORE); @@ -539,7 +539,7 @@ public void messageQueueChanged(String topic, Set mqAll, Set>> it = + Iterator>> it = messageQueueTreeSetMap.entrySet().iterator(); while (it.hasNext()) { if (!mqDivided.contains(it.next().getKey())) { diff --git a/extensions-contrib/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQProducerMain.java b/extensions-contrib/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQProducerMain.java index 0d470ee5811a..a6c68831906b 100644 --- a/extensions-contrib/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQProducerMain.java +++ b/extensions-contrib/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQProducerMain.java @@ -34,7 +34,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; -import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Random; @@ -115,13 +114,11 @@ public static void main(String[] args) // An extremely silly hack to maintain the above order in the help formatting. HelpFormatter formatter = new HelpFormatter(); // Add a comparator to the HelpFormatter using the ArrayList above to sort by insertion order. - formatter.setOptionComparator(new Comparator(){ - @Override - public int compare(Object o1, Object o2) - { - // I know this isn't fast, but who cares! The list is short. - return optionList.indexOf(o1) - optionList.indexOf(o2); - } + //noinspection ComparatorCombinators -- don't replace with comparingInt() to preserve comments + formatter.setOptionComparator((o1, o2) -> { + // I know this isn't fast, but who cares! The list is short. + //noinspection SuspiciousMethodCalls + return Integer.compare(optionList.indexOf(o1), optionList.indexOf(o2)); }); // Now we can add all the options to an Options instance. This is dumb! diff --git a/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogram.java b/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogram.java index 4a0cab96d359..50d941f0af22 100644 --- a/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogram.java +++ b/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogram.java @@ -1523,7 +1523,7 @@ public double sum(final float b) public float[] getQuantiles(float[] probabilities) { for (float p : probabilities) { - Preconditions.checkArgument(0 < p & p < 1, "quantile probabilities must be strictly between 0 and 1"); + Preconditions.checkArgument(0 < p && p < 1, "quantile probabilities must be strictly between 0 and 1"); } float[] quantiles = new float[probabilities.length]; diff --git a/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilePostAggregator.java b/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilePostAggregator.java index 3a12de65a528..649cbf640f56 100644 --- a/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilePostAggregator.java +++ b/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilePostAggregator.java @@ -59,7 +59,7 @@ public QuantilePostAggregator( this.probability = probability; this.fieldName = fieldName; - if (probability < 0 | probability > 1) { + if (probability < 0 || probability > 1) { throw new IAE("Illegal probability[%s], must be strictly between 0 and 1", probability); } } diff --git a/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilesPostAggregator.java b/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilesPostAggregator.java index 13127a575c6b..783b9947fa9a 100644 --- a/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilesPostAggregator.java +++ b/extensions-core/histogram/src/main/java/io/druid/query/aggregation/histogram/QuantilesPostAggregator.java @@ -50,7 +50,7 @@ public QuantilesPostAggregator( this.probabilities = probabilities; for (float p : probabilities) { - if (p < 0 | p > 1) { + if (p < 0 || p > 1) { throw new IAE("Illegal probability[%s], must be strictly between 0 and 1", p); } } diff --git a/extensions-core/histogram/src/test/java/io/druid/query/aggregation/histogram/ApproximateHistogramTest.java b/extensions-core/histogram/src/test/java/io/druid/query/aggregation/histogram/ApproximateHistogramTest.java index 71f293bcaa70..9d6d2347e26e 100644 --- a/extensions-core/histogram/src/test/java/io/druid/query/aggregation/histogram/ApproximateHistogramTest.java +++ b/extensions-core/histogram/src/test/java/io/druid/query/aggregation/histogram/ApproximateHistogramTest.java @@ -223,6 +223,8 @@ public void testFoldSpeed() //for(int i = 0; i < 200; ++i) h.offer((float)(rand.nextGaussian() * 50.0)); long tFold = 0; int count = 5000000; + // May be a bug that randNums are not used, should be resolved if testFoldSpeed() becomes a jUnit test again + @SuppressWarnings("MismatchedReadAndWriteOfArray") Float[] randNums = new Float[numRand]; for (int i = 0; i < numRand; i++) { randNums[i] = (float) rand.nextGaussian(); diff --git a/extensions-core/lookups-cached-global/src/test/java/io/druid/server/lookup/namespace/cache/CacheSchedulerTest.java b/extensions-core/lookups-cached-global/src/test/java/io/druid/server/lookup/namespace/cache/CacheSchedulerTest.java index bce4aeb316c2..61af9ac2007c 100644 --- a/extensions-core/lookups-cached-global/src/test/java/io/druid/server/lookup/namespace/cache/CacheSchedulerTest.java +++ b/extensions-core/lookups-cached-global/src/test/java/io/druid/server/lookup/namespace/cache/CacheSchedulerTest.java @@ -371,6 +371,7 @@ public void testShutdown() lifecycle.stop(); } while (!cacheManager.waitForServiceToEnd(1_000, TimeUnit.MILLISECONDS)) { + // keep waiting } checkNoMoreRunning(); @@ -395,6 +396,7 @@ public void testRunCount() throws InterruptedException, ExecutionException lifecycle.stop(); } while (!cacheManager.waitForServiceToEnd(1_000, TimeUnit.MILLISECONDS)) { + // keep waiting } Assert.assertTrue(scheduler.updatesStarted() >= numWaits); checkNoMoreRunning(); diff --git a/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/LoadingLookup.java b/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/LoadingLookup.java index 9e02077304dc..97e0acddaf83 100644 --- a/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/LoadingLookup.java +++ b/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/LoadingLookup.java @@ -146,4 +146,13 @@ public List call() throws Exception return dataFetcher.reverseFetchKeys(value); } } + + @Override + public String toString() + { + return "LoadingLookup{" + + "dataFetcher=" + dataFetcher + + ", id='" + id + '\'' + + '}'; + } } diff --git a/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/PollingLookup.java b/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/PollingLookup.java index ea641bf79fad..4bd0ad953b20 100644 --- a/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/PollingLookup.java +++ b/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/PollingLookup.java @@ -239,4 +239,12 @@ void doneWithIt() } } + @Override + public String toString() + { + return "PollingLookup{" + + "dataFetcher=" + dataFetcher + + ", id='" + id + '\'' + + '}'; + } } diff --git a/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/jdbc/JdbcDataFetcher.java b/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/jdbc/JdbcDataFetcher.java index c09ed11cacb5..28f5a7a362af 100644 --- a/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/jdbc/JdbcDataFetcher.java +++ b/extensions-core/lookups-cached-single/src/main/java/io/druid/server/lookup/jdbc/JdbcDataFetcher.java @@ -193,6 +193,16 @@ public boolean equals(Object o) } + @Override + public String toString() + { + return "JdbcDataFetcher{" + + "table='" + table + '\'' + + ", keyColumn='" + keyColumn + '\'' + + ", valueColumn='" + valueColumn + '\'' + + '}'; + } + private DBI getDbi() { return dbi; diff --git a/indexing-hadoop/src/test/java/io/druid/indexer/BucketTest.java b/indexing-hadoop/src/test/java/io/druid/indexer/BucketTest.java index c881d5bebf58..adf871413f59 100644 --- a/indexing-hadoop/src/test/java/io/druid/indexer/BucketTest.java +++ b/indexing-hadoop/src/test/java/io/druid/indexer/BucketTest.java @@ -72,8 +72,10 @@ public class BucketTest @Test public void testEquals() { + //noinspection ObjectEqualsNull Assert.assertFalse("Object should not be equals to NULL", bucket.equals(null)); - Assert.assertFalse("Objects do not have the same Class",bucket.equals(new Integer(0))); + //noinspection EqualsBetweenInconvertibleTypes + Assert.assertFalse("Objects do not have the same Class", bucket.equals(0)); Assert.assertFalse("Objects do not have the same partitionNum", bucket.equals(new Bucket(shardNum, time, partitionNum + 1))); Assert.assertFalse("Objects do not have the same shardNum", diff --git a/indexing-service/src/main/java/io/druid/indexing/common/task/AppendTask.java b/indexing-service/src/main/java/io/druid/indexing/common/task/AppendTask.java index b53a6cd64a14..98e0329163db 100644 --- a/indexing-service/src/main/java/io/druid/indexing/common/task/AppendTask.java +++ b/indexing-service/src/main/java/io/druid/indexing/common/task/AppendTask.java @@ -26,8 +26,8 @@ import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; import io.druid.indexing.common.TaskToolbox; +import io.druid.java.util.common.guava.Comparators; import io.druid.query.aggregation.AggregatorFactory; import io.druid.segment.IndexMerger; import io.druid.segment.IndexSpec; @@ -77,7 +77,7 @@ public File merge(final TaskToolbox toolbox, final Map segmen throws Exception { VersionedIntervalTimeline timeline = new VersionedIntervalTimeline( - Ordering.natural().nullsFirst() + Comparators.naturalNullsFirst() ); for (DataSegment segment : segments.keySet()) { diff --git a/indexing-service/src/main/java/io/druid/indexing/firehose/IngestSegmentFirehoseFactory.java b/indexing-service/src/main/java/io/druid/indexing/firehose/IngestSegmentFirehoseFactory.java index 11bc9bdfa26c..231c8b19ebdc 100644 --- a/indexing-service/src/main/java/io/druid/indexing/firehose/IngestSegmentFirehoseFactory.java +++ b/indexing-service/src/main/java/io/druid/indexing/firehose/IngestSegmentFirehoseFactory.java @@ -27,7 +27,6 @@ import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import com.google.inject.Injector; import com.metamx.emitter.EmittingLogger; @@ -38,6 +37,7 @@ import io.druid.indexing.common.TaskToolboxFactory; import io.druid.indexing.common.actions.SegmentListUsedAction; import io.druid.indexing.common.task.NoopTask; +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.parsers.ParseException; import io.druid.query.filter.DimFilter; import io.druid.segment.IndexIO; @@ -144,7 +144,7 @@ public Firehose connect(InputRowParser inputRowParser, File temporaryDirectory) .submit(new SegmentListUsedAction(dataSource, interval, null)); final Map segmentFileMap = taskToolbox.fetchSegments(usedSegments); VersionedIntervalTimeline timeline = new VersionedIntervalTimeline<>( - Ordering.natural().nullsFirst() + Comparators.naturalNullsFirst() ); for (DataSegment segment : usedSegments) { diff --git a/integration-tests/src/main/java/org/testng/TestNG.java b/integration-tests/src/main/java/org/testng/TestNG.java index f4076fc34037..170382b4e321 100644 --- a/integration-tests/src/main/java/org/testng/TestNG.java +++ b/integration-tests/src/main/java/org/testng/TestNG.java @@ -151,7 +151,7 @@ public class TestNG private static TestNG m_instance; - private static JCommander m_jCommander; + protected static JCommander m_jCommander; private List m_commandLineMethods; protected List m_suites = Lists.newArrayList(); diff --git a/integration-tests/src/main/java/org/testng/remote/RemoteTestNG.java b/integration-tests/src/main/java/org/testng/remote/RemoteTestNG.java index 1345ed7b8856..1f550fabbbc9 100644 --- a/integration-tests/src/main/java/org/testng/remote/RemoteTestNG.java +++ b/integration-tests/src/main/java/org/testng/remote/RemoteTestNG.java @@ -86,7 +86,7 @@ public static void main(String[] args) throws ParameterException { CommandLineArgs cla = new CommandLineArgs(); RemoteArgs ra = new RemoteArgs(); - new JCommander(Arrays.asList(cla, ra), args); + m_jCommander = new JCommander(Arrays.asList(cla, ra), args); m_dontExit = ra.dontExit; if (cla.port != null && ra.serPort != null) { throw new TestNGException( diff --git a/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java b/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java index 6b0a8e72a521..bdcfeb19cd07 100644 --- a/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java +++ b/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java @@ -19,16 +19,46 @@ package io.druid.java.util.common.guava; +import com.google.common.collect.Ordering; import com.google.common.primitives.Longs; import org.joda.time.DateTimeComparator; import org.joda.time.Interval; +import javax.annotation.Nullable; import java.util.Comparator; /** */ public class Comparators { + + private static final Ordering ALWAYS_EQUAL = new Ordering() + { + @SuppressWarnings("ComparatorMethodParameterNotUsed") + @Override + public int compare(@Nullable Object left, @Nullable Object right) + { + return 0; + } + }; + + //CHECKSTYLE.OFF: Regexp + // Ordering.natural().nullsFirst() is generally prohibited, but we need a single exception. + private static final Ordering NATURAL_NULLS_FIRST = Ordering.natural().nullsFirst(); + //CHECKSTYLE.ON: Regexp + + @SuppressWarnings("unchecked") + public static Ordering alwaysEqual() + { + return (Ordering) ALWAYS_EQUAL; + } + + @SuppressWarnings("unchecked") + public static > Ordering naturalNullsFirst() + { + return NATURAL_NULLS_FIRST; + } + /** * This is a "reverse" comparator. Positive becomes negative, negative becomes positive and 0 (equal) stays the same. * This was poorly named as "inverse" as it's not really inverting a true/false relationship 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 54e0b63b27ec..2300c58cd994 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,10 +21,10 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.collect.Ordering; import io.druid.hll.HyperLogLogCollector; import io.druid.java.util.common.IAE; import io.druid.java.util.common.StringUtils; +import io.druid.java.util.common.guava.Comparators; import io.druid.query.aggregation.Aggregator; import io.druid.query.aggregation.AggregatorFactory; import io.druid.query.aggregation.AggregatorFactoryNotMergeableException; @@ -122,7 +122,7 @@ public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) @Override public Comparator getComparator() { - return Ordering.natural().nullsFirst(); + return Comparators.naturalNullsFirst(); } @Override diff --git a/processing/src/main/java/io/druid/query/aggregation/post/ConstantPostAggregator.java b/processing/src/main/java/io/druid/query/aggregation/post/ConstantPostAggregator.java index cf9a4dfa25ae..b406b83a0fe4 100644 --- a/processing/src/main/java/io/druid/query/aggregation/post/ConstantPostAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/post/ConstantPostAggregator.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; +import io.druid.java.util.common.guava.Comparators; import io.druid.query.aggregation.AggregatorFactory; import io.druid.query.aggregation.PostAggregator; import io.druid.query.cache.CacheKeyBuilder; @@ -58,14 +59,7 @@ public Set getDependentFields() @Override public Comparator getComparator() { - return new Comparator() - { - @Override - public int compare(Object o1, Object o2) - { - return 0; - } - }; + return Comparators.alwaysEqual(); } @Override diff --git a/processing/src/main/java/io/druid/query/aggregation/post/FinalizingFieldAccessPostAggregator.java b/processing/src/main/java/io/druid/query/aggregation/post/FinalizingFieldAccessPostAggregator.java index be7d3b86c351..48c961eb3f91 100644 --- a/processing/src/main/java/io/druid/query/aggregation/post/FinalizingFieldAccessPostAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/post/FinalizingFieldAccessPostAggregator.java @@ -22,8 +22,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Ordering; import com.google.common.collect.Sets; +import io.druid.java.util.common.guava.Comparators; import io.druid.query.aggregation.AggregatorFactory; import io.druid.query.aggregation.PostAggregator; import io.druid.query.cache.CacheKeyBuilder; @@ -83,7 +83,7 @@ public Comparator getComparator() if (aggregators != null && aggregators.containsKey(fieldName)) { return aggregators.get(fieldName).getComparator(); } else { - return Ordering.natural().nullsFirst(); + return Comparators.naturalNullsFirst(); } } diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java b/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java index 893bdd13d26f..30efe3ac725d 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java @@ -36,6 +36,7 @@ import io.druid.java.util.common.ISE; import io.druid.java.util.common.granularity.Granularities; import io.druid.java.util.common.granularity.Granularity; +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.guava.Sequence; import io.druid.java.util.common.guava.Sequences; import io.druid.query.BaseQuery; @@ -81,8 +82,6 @@ public class GroupByQuery extends BaseQuery { public final static String CTX_KEY_SORT_BY_DIMS_FIRST = "sortByDimsFirst"; - private final static Comparator NATURAL_NULLS_FIRST = Ordering.natural().nullsFirst(); - private final static Comparator NON_GRANULAR_TIME_COMP = (Row lhs, Row rhs) -> Longs.compare( lhs.getTimestampFromEpoch(), rhs.getTimestampFromEpoch() @@ -327,7 +326,7 @@ public Ordering getResultOrdering() return rowOrdering.compare((Row) lhs, (Row) rhs); } else { // Probably bySegment queries - return NATURAL_NULLS_FIRST.compare(lhs, rhs); + return ((Ordering) Comparators.naturalNullsFirst()).compare(lhs, rhs); } } ); @@ -563,7 +562,7 @@ private static int compareDims(List dimensions, Row lhs, Row rhs) ((Number) rhs.getRaw(dimension.getOutputName())).doubleValue() ); } else { - dimCompare = NATURAL_NULLS_FIRST.compare( + dimCompare = ((Ordering) Comparators.naturalNullsFirst()).compare( lhs.getRaw(dimension.getOutputName()), rhs.getRaw(dimension.getOutputName()) ); @@ -603,7 +602,7 @@ private static int compareDimsForLimitPushDown( if (isNumericField.get(i)) { if (comparator == StringComparators.NUMERIC) { - dimCompare = NATURAL_NULLS_FIRST.compare( + dimCompare = ((Ordering) Comparators.naturalNullsFirst()).compare( rhs.getRaw(fieldName), lhs.getRaw(fieldName) ); diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQueryConfig.java b/processing/src/main/java/io/druid/query/groupby/GroupByQueryConfig.java index 6f55b9a2abc7..1475239d9041 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryConfig.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryConfig.java @@ -184,4 +184,20 @@ public GroupByQueryConfig withOverrides(final GroupByQuery query) newConfig.forcePushDownLimit = query.getContextBoolean(CTX_KEY_FORCE_LIMIT_PUSH_DOWN, isForcePushDownLimit()); return newConfig; } + + @Override + public String toString() + { + return "GroupByQueryConfig{" + + "defaultStrategy='" + defaultStrategy + '\'' + + ", singleThreaded=" + singleThreaded + + ", maxIntermediateRows=" + maxIntermediateRows + + ", maxResults=" + maxResults + + ", bufferGrouperMaxSize=" + bufferGrouperMaxSize + + ", bufferGrouperMaxLoadFactor=" + bufferGrouperMaxLoadFactor + + ", bufferGrouperInitialBuckets=" + bufferGrouperInitialBuckets + + ", maxMergingDictionarySize=" + maxMergingDictionarySize + + ", maxOnDiskStorage=" + maxOnDiskStorage + + '}'; + } } diff --git a/processing/src/main/java/io/druid/query/lookup/LookupExtractionFn.java b/processing/src/main/java/io/druid/query/lookup/LookupExtractionFn.java index cc13b93f704b..e2a5d992fe68 100644 --- a/processing/src/main/java/io/druid/query/lookup/LookupExtractionFn.java +++ b/processing/src/main/java/io/druid/query/lookup/LookupExtractionFn.java @@ -162,4 +162,16 @@ public int hashCode() result = 31 * result + (isInjective() ? 1 : 0); return result; } + + @Override + public String toString() + { + return "LookupExtractionFn{" + + "lookup=" + lookup + + ", optimize=" + optimize + + ", retainMissingValue=" + retainMissingValue + + ", replaceMissingValueWith='" + replaceMissingValueWith + '\'' + + ", injective=" + injective + + '}'; + } } diff --git a/processing/src/main/java/io/druid/query/lookup/LookupExtractorFactoryContainer.java b/processing/src/main/java/io/druid/query/lookup/LookupExtractorFactoryContainer.java index 6d9f73d92113..76719d582b52 100644 --- a/processing/src/main/java/io/druid/query/lookup/LookupExtractorFactoryContainer.java +++ b/processing/src/main/java/io/druid/query/lookup/LookupExtractorFactoryContainer.java @@ -22,7 +22,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Preconditions; -import com.google.common.collect.Ordering; +import io.druid.java.util.common.guava.Comparators; import java.util.Objects; @@ -30,8 +30,6 @@ */ public class LookupExtractorFactoryContainer { - private final static Ordering VERSION_COMPARATOR = Ordering.natural().nullsFirst(); - private final String version; private final LookupExtractorFactory lookupExtractorFactory; @@ -62,7 +60,7 @@ public boolean replaces(LookupExtractorFactoryContainer other) { return this.lookupExtractorFactory.replaces(other.getLookupExtractorFactory()); } - return VERSION_COMPARATOR.compare(version, other.getVersion()) > 0; + return Comparators.naturalNullsFirst().compare(version, other.getVersion()) > 0; } @Override diff --git a/processing/src/main/java/io/druid/query/metadata/SegmentMetadataQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/metadata/SegmentMetadataQueryQueryToolChest.java index 071c6e84d3af..215d0a4053bd 100644 --- a/processing/src/main/java/io/druid/query/metadata/SegmentMetadataQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/metadata/SegmentMetadataQueryQueryToolChest.java @@ -35,6 +35,7 @@ import io.druid.common.utils.JodaUtils; import io.druid.data.input.impl.TimestampSpec; import io.druid.java.util.common.granularity.Granularity; +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.guava.MappedSequence; import io.druid.java.util.common.guava.Sequence; import io.druid.java.util.common.guava.nary.BinaryFn; @@ -126,16 +127,7 @@ private Ordering makeOrdering(SegmentMetadataQuery query) { if (query.isMerge()) { // Merge everything always - return new Ordering() - { - @Override - public int compare( - @Nullable SegmentAnalysis left, @Nullable SegmentAnalysis right - ) - { - return 0; - } - }; + return Comparators.alwaysEqual(); } return query.getResultOrdering(); // No two elements should be equal, so it should never merge diff --git a/processing/src/main/java/io/druid/query/ordering/StringComparators.java b/processing/src/main/java/io/druid/query/ordering/StringComparators.java index de43ce2b9ed1..2a66b3c05592 100644 --- a/processing/src/main/java/io/druid/query/ordering/StringComparators.java +++ b/processing/src/main/java/io/druid/query/ordering/StringComparators.java @@ -57,12 +57,12 @@ public int compare(String s, String s2) } }).nullsFirst(); - @SuppressWarnings("StringEquality") @Override public int compare(String s, String s2) { // Avoid conversion to bytes for equal references // Assuming we mostly compare different strings, checking s.equals(s2) will only make the comparison slower. + //noinspection StringEquality if (s == s2) { return 0; } @@ -319,10 +319,12 @@ public int compare(String s, String s2) return Ints.compare(s.length(), s2.length()); } }).nullsFirst().compound(Ordering.natural()); - + @Override public int compare(String s, String s2) { + // Optimization + //noinspection StringEquality if (s == s2) { return 0; } @@ -372,12 +374,12 @@ private static BigDecimal convertStringToBigDecimal(String input) { public static class NumericComparator extends StringComparator { - @SuppressWarnings("StringEquality") @Override public int compare(String o1, String o2) { // return if o1 and o2 are the same object // Assuming we mostly compare different strings, checking o1.equals(o2) will only make the comparison slower. + //noinspection StringEquality if (o1 == o2) { return 0; } diff --git a/processing/src/main/java/io/druid/segment/IndexMerger.java b/processing/src/main/java/io/druid/segment/IndexMerger.java index 8c8e3be841b9..3251232a74b6 100644 --- a/processing/src/main/java/io/druid/segment/IndexMerger.java +++ b/processing/src/main/java/io/druid/segment/IndexMerger.java @@ -46,6 +46,7 @@ import io.druid.java.util.common.IAE; import io.druid.java.util.common.ISE; import io.druid.java.util.common.Pair; +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.guava.FunctionalIterable; import io.druid.java.util.common.guava.MergeIterable; import io.druid.java.util.common.guava.nary.BinaryFn; @@ -410,11 +411,8 @@ public Iterable apply( { if (rollup) { return CombiningIterable.create( - new MergeIterable( - Ordering.natural().nullsFirst(), - boats - ), - Ordering.natural().nullsFirst(), + new MergeIterable<>(Comparators.naturalNullsFirst(), boats), + Comparators.naturalNullsFirst(), new RowboatMergeFunction(sortedMetricAggs) ); } else { @@ -530,10 +528,7 @@ public Iterable apply( @Nullable final ArrayList> boats ) { - return new MergeIterable( - Ordering.natural().nullsFirst(), - boats - ); + return new MergeIterable<>(Comparators.naturalNullsFirst(), boats); } }; @@ -590,8 +585,8 @@ public Metadata apply(IndexableAdapter input) ); } - final Map valueTypes = Maps.newTreeMap(Ordering.natural().nullsFirst()); - final Map metricTypeNames = Maps.newTreeMap(Ordering.natural().nullsFirst()); + final Map valueTypes = Maps.newTreeMap(Comparators.naturalNullsFirst()); + final Map metricTypeNames = Maps.newTreeMap(Comparators.naturalNullsFirst()); final Map columnCapabilities = Maps.newHashMap(); final List dimCapabilities = new ArrayList<>(); @@ -1019,9 +1014,9 @@ private boolean isSame(Indexed indexed, List values) return true; } - public static ArrayList mergeIndexed(final List> indexedLists) + public static > ArrayList mergeIndexed(final List> indexedLists) { - Set retVal = Sets.newTreeSet(Ordering.natural().nullsFirst()); + Set retVal = Sets.newTreeSet(Comparators.naturalNullsFirst()); for (Iterable indexedList : indexedLists) { for (T val : indexedList) { @@ -1349,10 +1344,12 @@ boolean needConversion(int index) { IntBuffer readOnly = conversions[index].asReadOnlyBuffer(); readOnly.rewind(); - for (int i = 0; readOnly.hasRemaining(); i++) { + int i = 0; + while (readOnly.hasRemaining()) { if (i != readOnly.get()) { return true; } + i++; } return false; } diff --git a/processing/src/main/java/io/druid/segment/IndexMergerV9.java b/processing/src/main/java/io/druid/segment/IndexMergerV9.java index 81ca1123d99c..f470b15b4d74 100644 --- a/processing/src/main/java/io/druid/segment/IndexMergerV9.java +++ b/processing/src/main/java/io/druid/segment/IndexMergerV9.java @@ -23,16 +23,16 @@ import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import com.google.common.io.ByteStreams; import com.google.common.io.Files; import com.google.common.primitives.Ints; import com.google.inject.Inject; import io.druid.common.utils.JodaUtils; -import io.druid.java.util.common.io.Closer; import io.druid.io.ZeroCopyByteArrayOutputStream; import io.druid.java.util.common.ISE; +import io.druid.java.util.common.guava.Comparators; +import io.druid.java.util.common.io.Closer; import io.druid.java.util.common.io.smoosh.FileSmoosher; import io.druid.java.util.common.io.smoosh.SmooshedWriter; import io.druid.java.util.common.logger.Logger; @@ -157,8 +157,8 @@ public Metadata apply(IndexableAdapter input) log.info("Completed factory.json in %,d millis", System.currentTimeMillis() - startTime); progress.progress(); - final Map metricsValueTypes = Maps.newTreeMap(Ordering.natural().nullsFirst()); - final Map metricTypeNames = Maps.newTreeMap(Ordering.natural().nullsFirst()); + final Map metricsValueTypes = Maps.newTreeMap(Comparators.naturalNullsFirst()); + final Map metricTypeNames = Maps.newTreeMap(Comparators.naturalNullsFirst()); final List dimCapabilities = Lists.newArrayListWithCapacity(mergedDimensions.size()); mergeCapabilities(adapters, mergedDimensions, metricsValueTypes, metricTypeNames, dimCapabilities); diff --git a/processing/src/main/java/io/druid/segment/IndexSpec.java b/processing/src/main/java/io/druid/segment/IndexSpec.java index 78ea341f063c..cbdb51e55255 100644 --- a/processing/src/main/java/io/druid/segment/IndexSpec.java +++ b/processing/src/main/java/io/druid/segment/IndexSpec.java @@ -30,6 +30,7 @@ import io.druid.segment.data.ConciseBitmapSerdeFactory; import java.util.Arrays; +import java.util.Objects; import java.util.Set; /** @@ -143,30 +144,27 @@ public boolean equals(Object o) if (o == null || getClass() != o.getClass()) { return false; } - IndexSpec indexSpec = (IndexSpec) o; - - if (bitmapSerdeFactory != null - ? !bitmapSerdeFactory.equals(indexSpec.bitmapSerdeFactory) - : indexSpec.bitmapSerdeFactory != null) { - return false; - } - if (dimensionCompression != null - ? !dimensionCompression.equals(indexSpec.dimensionCompression) - : indexSpec.dimensionCompression != null) { - return false; - } - return !(metricCompression != null - ? !metricCompression.equals(indexSpec.metricCompression) - : indexSpec.metricCompression != null); + return Objects.equals(bitmapSerdeFactory, indexSpec.bitmapSerdeFactory) && + dimensionCompression == indexSpec.dimensionCompression && + metricCompression == indexSpec.metricCompression && + longEncoding == indexSpec.longEncoding; } @Override public int hashCode() { - int result = bitmapSerdeFactory != null ? bitmapSerdeFactory.hashCode() : 0; - result = 31 * result + (dimensionCompression != null ? dimensionCompression.hashCode() : 0); - result = 31 * result + (metricCompression != null ? metricCompression.hashCode() : 0); - return result; + return Objects.hash(bitmapSerdeFactory, dimensionCompression, metricCompression, longEncoding); + } + + @Override + public String toString() + { + return "IndexSpec{" + + "bitmapSerdeFactory=" + bitmapSerdeFactory + + ", dimensionCompression=" + dimensionCompression + + ", metricCompression=" + metricCompression + + ", longEncoding=" + longEncoding + + '}'; } } diff --git a/processing/src/main/java/io/druid/segment/StringDimensionHandler.java b/processing/src/main/java/io/druid/segment/StringDimensionHandler.java index c017841f2e86..14a42b0f74cb 100644 --- a/processing/src/main/java/io/druid/segment/StringDimensionHandler.java +++ b/processing/src/main/java/io/druid/segment/StringDimensionHandler.java @@ -81,7 +81,7 @@ public void validateSortedEncodedKeyComponents( ) throws SegmentValidationException { if (lhs == null || rhs == null) { - if (lhs != rhs) { + if (lhs != null || rhs != null) { throw new SegmentValidationException( "Expected nulls, found %s and %s", Arrays.toString(lhs), diff --git a/processing/src/main/java/io/druid/segment/StringDimensionIndexer.java b/processing/src/main/java/io/druid/segment/StringDimensionIndexer.java index 956a28a5feff..3fac362f9114 100644 --- a/processing/src/main/java/io/druid/segment/StringDimensionIndexer.java +++ b/processing/src/main/java/io/druid/segment/StringDimensionIndexer.java @@ -24,12 +24,12 @@ import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Ordering; import com.google.common.primitives.Ints; import io.druid.collections.bitmap.BitmapFactory; import io.druid.collections.bitmap.MutableBitmap; import io.druid.data.input.impl.DimensionSchema.MultiValueHandling; import io.druid.java.util.common.ISE; +import io.druid.java.util.common.guava.Comparators; import io.druid.query.dimension.DimensionSpec; import io.druid.query.extraction.ExtractionFn; import io.druid.query.filter.ValueMatcher; @@ -51,7 +51,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; -import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -61,8 +60,6 @@ public class StringDimensionIndexer implements DimensionIndexer STRING_TRANSFORMER = o -> o != null ? o.toString() : null; - private static final Comparator UNENCODED_COMPARATOR = Ordering.natural().nullsFirst(); - private static class DimensionDictionary { private String minValue = null; @@ -227,7 +224,7 @@ public int[] processRowValsToUnsortedEncodedKeyComponent(Object dimValues) } if (multiValueHandling.needSorting()) { // Sort multival row by their unencoded values first. - Arrays.sort(dimensionValues, UNENCODED_COMPARATOR); + Arrays.sort(dimensionValues, Comparators.naturalNullsFirst()); } final int[] retVal = new int[dimensionValues.length]; diff --git a/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java b/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java index a1f6346dedc0..36da8097e578 100644 --- a/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java +++ b/processing/src/main/java/io/druid/segment/data/BitmapCompressedIndexedInts.java @@ -32,7 +32,7 @@ */ public class BitmapCompressedIndexedInts implements IndexedInts, Comparable { - private static Ordering comparator = new Ordering() + private static final Ordering COMPARATOR = new Ordering() { @Override public int compare( @@ -62,7 +62,7 @@ public BitmapCompressedIndexedInts(ImmutableBitmap immutableBitmap) @Override public int compareTo(@Nullable ImmutableBitmap otherBitmap) { - return comparator.compare(immutableBitmap, otherBitmap); + return COMPARATOR.compare(immutableBitmap, otherBitmap); } @Override diff --git a/processing/src/main/java/io/druid/segment/data/CompressedByteBufferObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/CompressedByteBufferObjectStrategy.java index 5d411477a1a8..96afb159c784 100644 --- a/processing/src/main/java/io/druid/segment/data/CompressedByteBufferObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/CompressedByteBufferObjectStrategy.java @@ -19,14 +19,13 @@ package io.druid.segment.data; -import com.google.common.collect.Ordering; +import io.druid.java.util.common.guava.Comparators; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class CompressedByteBufferObjectStrategy extends FixedSizeCompressedObjectStrategy { - public static final Ordering ORDERING = Ordering.natural().nullsFirst(); public static CompressedByteBufferObjectStrategy getBufferForOrder(final ByteOrder order, final CompressionStrategy compression, final int sizePer) { @@ -51,7 +50,7 @@ public ByteBuffer convert(ByteBuffer buf) @Override public int compare(ByteBuffer lhs, ByteBuffer rhs) { - return ORDERING.compare(lhs, rhs); + return Comparators.naturalNullsFirst().compare(lhs, rhs); } @Override diff --git a/processing/src/main/java/io/druid/segment/data/CompressedFloatBufferObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/CompressedFloatBufferObjectStrategy.java index f3fb3a9dea02..09bb6b5819d8 100644 --- a/processing/src/main/java/io/druid/segment/data/CompressedFloatBufferObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/CompressedFloatBufferObjectStrategy.java @@ -19,8 +19,8 @@ package io.druid.segment.data; -import com.google.common.collect.Ordering; import com.google.common.primitives.Floats; +import io.druid.java.util.common.guava.Comparators; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -50,7 +50,7 @@ public FloatBuffer convert(ByteBuffer buf) @Override public int compare(FloatBuffer lhs, FloatBuffer rhs) { - return Ordering.natural().nullsFirst().compare(lhs, rhs); + return Comparators.naturalNullsFirst().compare(lhs, rhs); } @Override diff --git a/processing/src/main/java/io/druid/segment/data/CompressedIntBufferObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/CompressedIntBufferObjectStrategy.java index ea1da5c92451..b3fd010d0ee8 100644 --- a/processing/src/main/java/io/druid/segment/data/CompressedIntBufferObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/CompressedIntBufferObjectStrategy.java @@ -19,8 +19,8 @@ package io.druid.segment.data; -import com.google.common.collect.Ordering; import com.google.common.primitives.Ints; +import io.druid.java.util.common.guava.Comparators; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -28,7 +28,6 @@ public class CompressedIntBufferObjectStrategy extends FixedSizeCompressedObjectStrategy { - public static final Ordering ORDERING = Ordering.natural().nullsFirst(); public static CompressedIntBufferObjectStrategy getBufferForOrder(final ByteOrder order, final CompressionStrategy compression, final int sizePer) { @@ -50,7 +49,7 @@ public IntBuffer convert(ByteBuffer buf) @Override public int compare(IntBuffer lhs, IntBuffer rhs) { - return ORDERING.compare(lhs, rhs); + return Comparators.naturalNullsFirst().compare(lhs, rhs); } @Override diff --git a/processing/src/main/java/io/druid/segment/data/CompressedLongBufferObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/CompressedLongBufferObjectStrategy.java index 5ed3eb99531f..e43e1eae12bb 100644 --- a/processing/src/main/java/io/druid/segment/data/CompressedLongBufferObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/CompressedLongBufferObjectStrategy.java @@ -19,8 +19,8 @@ package io.druid.segment.data; -import com.google.common.collect.Ordering; import com.google.common.primitives.Longs; +import io.druid.java.util.common.guava.Comparators; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -50,7 +50,7 @@ public LongBuffer convert(ByteBuffer buf) @Override public int compare(LongBuffer lhs, LongBuffer rhs) { - return Ordering.natural().nullsFirst().compare(lhs, rhs); + return Comparators.naturalNullsFirst().compare(lhs, rhs); } @Override diff --git a/processing/src/main/java/io/druid/segment/data/GenericIndexed.java b/processing/src/main/java/io/druid/segment/data/GenericIndexed.java index 61f3395049cb..2922786eccee 100644 --- a/processing/src/main/java/io/druid/segment/data/GenericIndexed.java +++ b/processing/src/main/java/io/druid/segment/data/GenericIndexed.java @@ -19,13 +19,13 @@ package io.druid.segment.data; -import com.google.common.collect.Ordering; import com.google.common.primitives.Ints; import io.druid.common.utils.SerializerUtils; import io.druid.io.ZeroCopyByteArrayOutputStream; import io.druid.java.util.common.IAE; import io.druid.java.util.common.StringUtils; import io.druid.java.util.common.guava.CloseQuietly; +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.io.smoosh.SmooshedFileMapper; import io.druid.query.monomorphicprocessing.RuntimeShapeInspector; import it.unimi.dsi.fastutil.bytes.ByteArrays; @@ -73,7 +73,6 @@ public class GenericIndexed implements Indexed static final byte VERSION_TWO = 0x2; static final byte REVERSE_LOOKUP_ALLOWED = 0x1; static final byte REVERSE_LOOKUP_DISALLOWED = 0x0; - private final static Ordering NATURAL_STRING_ORDERING = Ordering.natural().nullsFirst(); private static final SerializerUtils SERIALIZER_UTILS = new SerializerUtils(); public static final ObjectStrategy STRING_STRATEGY = new CacheableObjectStrategy() @@ -102,7 +101,7 @@ public byte[] toBytes(String val) @Override public int compare(String o1, String o2) { - return NATURAL_STRING_ORDERING.compare(o1, o2); + return Comparators.naturalNullsFirst().compare(o1, o2); } }; diff --git a/processing/src/main/java/io/druid/segment/data/VSizeCompressedObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/VSizeCompressedObjectStrategy.java index e082579d3503..1595e2b9af3a 100644 --- a/processing/src/main/java/io/druid/segment/data/VSizeCompressedObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/VSizeCompressedObjectStrategy.java @@ -19,6 +19,8 @@ package io.druid.segment.data; +import io.druid.java.util.common.guava.Comparators; + import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -53,7 +55,7 @@ public ByteBuffer convert(ByteBuffer buf) @Override public int compare(ByteBuffer lhs, ByteBuffer rhs) { - return CompressedByteBufferObjectStrategy.ORDERING.compare(lhs, rhs); + return Comparators.naturalNullsFirst().compare(lhs, rhs); } @Override diff --git a/processing/src/main/java/io/druid/segment/filter/ColumnComparisonFilter.java b/processing/src/main/java/io/druid/segment/filter/ColumnComparisonFilter.java index 13a39fe65c82..83d5890416e0 100644 --- a/processing/src/main/java/io/druid/segment/filter/ColumnComparisonFilter.java +++ b/processing/src/main/java/io/druid/segment/filter/ColumnComparisonFilter.java @@ -113,7 +113,7 @@ public void inspectRuntimeShape(RuntimeShapeInspector inspector) public static boolean overlap(String[] a, String[] b) { if (a == null || b == null) { // They only have overlap if both are null. - return a == b; + return a == null && b == null; } if (a.length == 0 && b.length == 0) { return true; diff --git a/processing/src/main/java/io/druid/segment/serde/DictionaryEncodedColumnPartSerde.java b/processing/src/main/java/io/druid/segment/serde/DictionaryEncodedColumnPartSerde.java index a306357b44dc..f3eff916ce97 100644 --- a/processing/src/main/java/io/druid/segment/serde/DictionaryEncodedColumnPartSerde.java +++ b/processing/src/main/java/io/druid/segment/serde/DictionaryEncodedColumnPartSerde.java @@ -506,9 +506,10 @@ private WritableSupplier> readMultiValuedColumn( ) { switch (version) { - case UNCOMPRESSED_MULTI_VALUE: + case UNCOMPRESSED_MULTI_VALUE: { return VSizeIndexed.readFromByteBuffer(buffer).asWritableSupplier(); - case COMPRESSED: + } + case COMPRESSED: { if (Feature.MULTI_VALUE.isSet(flags)) { return CompressedVSizeIndexedSupplier.fromByteBuffer(buffer, byteOrder, fileMapper); } else if (Feature.MULTI_VALUE_V3.isSet(flags)) { @@ -516,6 +517,7 @@ private WritableSupplier> readMultiValuedColumn( } else { throw new IAE("Unrecognized multi-value flag[%d]", flags); } + } default: throw new IAE("Unsupported multi-value version[%s]", version); } diff --git a/processing/src/test/java/io/druid/query/cache/CacheKeyBuilderTest.java b/processing/src/test/java/io/druid/query/cache/CacheKeyBuilderTest.java index 1619fd044e52..9ad874985a00 100644 --- a/processing/src/test/java/io/druid/query/cache/CacheKeyBuilderTest.java +++ b/processing/src/test/java/io/druid/query/cache/CacheKeyBuilderTest.java @@ -286,11 +286,9 @@ public byte[] getCacheKey() private static void assertNotEqualsEachOther(List keys) { - for (byte[] k1 : keys) { - for (byte[] k2 : keys) { - if (k1 != k2) { - assertFalse(Arrays.equals(k1, k2)); - } + for (int i = 0; i < keys.size(); i++) { + for (int j = i + 1; j < keys.size(); j++) { + assertFalse(Arrays.equals(keys.get(i), keys.get(j))); } } } diff --git a/processing/src/test/java/io/druid/query/groupby/epinephelinae/ByteBufferMinMaxOffsetHeapTest.java b/processing/src/test/java/io/druid/query/groupby/epinephelinae/ByteBufferMinMaxOffsetHeapTest.java index 336c1b2fc16a..cb0159e1f169 100644 --- a/processing/src/test/java/io/druid/query/groupby/epinephelinae/ByteBufferMinMaxOffsetHeapTest.java +++ b/processing/src/test/java/io/druid/query/groupby/epinephelinae/ByteBufferMinMaxOffsetHeapTest.java @@ -21,6 +21,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Ordering; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import org.junit.Assert; import org.junit.Test; @@ -195,9 +197,9 @@ public void testRemove() { int limit = 100; - ArrayList values = Lists.newArrayList( + IntList values = new IntArrayList(new int[] { 1, 20, 1000, 2, 3, 30, 40, 10, 11, 12, 13, 300, 400, 500, 600 - ); + }); ByteBuffer myBuffer = ByteBuffer.allocate(1000000); ByteBufferMinMaxOffsetHeap heap = new ByteBufferMinMaxOffsetHeap(myBuffer, limit, Ordering.natural(), null); @@ -212,7 +214,7 @@ public void testRemove() Assert.assertTrue(heap.isIntact()); Collections.sort(values); - values.remove((Number) 12); + values.rem(12); List actual = Lists.newArrayList(); for (int i = 0; i < values.size(); i++){ @@ -228,10 +230,10 @@ public void testRemove2() { int limit = 100; - ArrayList values = Lists.newArrayList( + IntList values = new IntArrayList(new int[] { 1, 20, 1000, 2, 3, 30, 40, 10, 11, 12, 13, 300, 400, 500, 600, 4, 5, 6, 7, 8, 9, 4, 5, 200, 250 - ); + }); ByteBuffer myBuffer = ByteBuffer.allocate(1000000); ByteBufferMinMaxOffsetHeap heap = new ByteBufferMinMaxOffsetHeap(myBuffer, limit, Ordering.natural(), null); @@ -245,7 +247,7 @@ public void testRemove2() Assert.assertTrue(heap.isIntact()); Collections.sort(values); - values.remove((Number) 2); + values.rem(2); Assert.assertTrue(heap.isIntact()); List actual = Lists.newArrayList(); diff --git a/processing/src/test/java/io/druid/segment/SchemalessIndexTest.java b/processing/src/test/java/io/druid/segment/SchemalessIndexTest.java index 2d4fe6625bac..724a609b6501 100644 --- a/processing/src/test/java/io/druid/segment/SchemalessIndexTest.java +++ b/processing/src/test/java/io/druid/segment/SchemalessIndexTest.java @@ -26,12 +26,12 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Ordering; import io.druid.data.input.MapBasedInputRow; import io.druid.hll.HyperLogLogHash; import io.druid.jackson.DefaultObjectMapper; import io.druid.java.util.common.Pair; import io.druid.java.util.common.granularity.Granularities; +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.logger.Logger; import io.druid.query.aggregation.AggregatorFactory; import io.druid.query.aggregation.CountAggregatorFactory; @@ -444,7 +444,7 @@ private static QueryableIndex makeAppendedMMappedIndex( List filesToMap = makeFilesToMap(tmpFile, files); VersionedIntervalTimeline timeline = new VersionedIntervalTimeline( - Ordering.natural().nullsFirst() + Comparators.naturalNullsFirst() ); ShardSpec noneShardSpec = NoneShardSpec.instance(); diff --git a/server/src/main/java/io/druid/client/DirectDruidClient.java b/server/src/main/java/io/druid/client/DirectDruidClient.java index 49006a8f79b8..b8f1f2600b0e 100644 --- a/server/src/main/java/io/druid/client/DirectDruidClient.java +++ b/server/src/main/java/io/druid/client/DirectDruidClient.java @@ -645,4 +645,13 @@ public void close() throws IOException } } } + + @Override + public String toString() + { + return "DirectDruidClient{" + + "host='" + host + '\'' + + ", isSmile=" + isSmile + + '}'; + } } diff --git a/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java b/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java index beced264b159..b1fc363ee1fb 100644 --- a/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java +++ b/server/src/main/java/io/druid/segment/indexing/granularity/ArbitraryGranularitySpec.java @@ -172,6 +172,16 @@ public int hashCode() return result; } + @Override + public String toString() + { + return "ArbitraryGranularitySpec{" + + "intervals=" + intervals + + ", queryGranularity=" + queryGranularity + + ", rollup=" + rollup + + '}'; + } + @Override public GranularitySpec withIntervals(List inputIntervals) { return new ArbitraryGranularitySpec(queryGranularity, rollup, inputIntervals); diff --git a/server/src/main/java/io/druid/segment/realtime/FireHydrant.java b/server/src/main/java/io/druid/segment/realtime/FireHydrant.java index 35cc878b8cfe..afcd10d18420 100644 --- a/server/src/main/java/io/druid/segment/realtime/FireHydrant.java +++ b/server/src/main/java/io/druid/segment/realtime/FireHydrant.java @@ -120,7 +120,7 @@ public String toString() { return "FireHydrant{" + "index=" + index + - ", queryable=" + adapter + + ", queryable=" + adapter.getIdentifier() + ", count=" + count + '}'; } diff --git a/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java b/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java index e0e4b2d45b52..e1ad95f6b5ef 100644 --- a/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java +++ b/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java @@ -145,6 +145,7 @@ public static double intervalCost(double x1, double y0, double y1) beta = x1 - y0; gamma = y1 - y0; } + //noinspection SuspiciousNameCombination return intervalCost(y0, y0, y1) + // cost(A, Y) intervalCost(beta, beta, gamma) + // cost(B, C) 2 * (beta + FastMath.exp(-beta) - 1); // cost(B, B) diff --git a/server/src/main/java/io/druid/server/lookup/cache/LookupExtractorFactoryMapContainer.java b/server/src/main/java/io/druid/server/lookup/cache/LookupExtractorFactoryMapContainer.java index d89d9c6315e3..b90af36fe68c 100644 --- a/server/src/main/java/io/druid/server/lookup/cache/LookupExtractorFactoryMapContainer.java +++ b/server/src/main/java/io/druid/server/lookup/cache/LookupExtractorFactoryMapContainer.java @@ -22,7 +22,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Preconditions; -import com.google.common.collect.Ordering; +import io.druid.java.util.common.guava.Comparators; import java.util.Map; import java.util.Objects; @@ -34,8 +34,6 @@ */ public class LookupExtractorFactoryMapContainer { - private final static Ordering VERSION_COMPARATOR = Ordering.natural().nullsFirst(); - private final String version; private final Map lookupExtractorFactory; @@ -66,7 +64,7 @@ public boolean replaces(LookupExtractorFactoryMapContainer other) { return false; } - return VERSION_COMPARATOR.compare(version, other.getVersion()) > 0; + return Comparators.naturalNullsFirst().compare(version, other.getVersion()) > 0; } @Override diff --git a/server/src/test/java/io/druid/client/CachingClusteredClientTest.java b/server/src/test/java/io/druid/client/CachingClusteredClientTest.java index 11482fb898c0..77d25cbddbff 100644 --- a/server/src/test/java/io/druid/client/CachingClusteredClientTest.java +++ b/server/src/test/java/io/druid/client/CachingClusteredClientTest.java @@ -60,6 +60,7 @@ import io.druid.java.util.common.granularity.Granularities; import io.druid.java.util.common.granularity.Granularity; import io.druid.java.util.common.granularity.PeriodGranularity; +import io.druid.java.util.common.guava.Comparators; import io.druid.java.util.common.guava.FunctionalIterable; import io.druid.java.util.common.guava.MergeIterable; import io.druid.java.util.common.guava.Sequence; @@ -2167,7 +2168,7 @@ public void run() for (int i = 0; i < numTimesToQuery; ++i) { TestHelper.assertExpectedResults( new MergeIterable<>( - Ordering.>natural().nullsFirst(), + Comparators.naturalNullsFirst(), FunctionalIterable .create(new RangeIterable(expectedResultsRangeStart, expectedResultsRangeEnd)) .transformCat(