diff --git a/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java b/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java index 44dc34ca3d2a..be7b0f479e06 100644 --- a/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java +++ b/extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSource.java @@ -62,6 +62,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -161,7 +162,7 @@ public InputSourceReader reader( final StructType fullSnapshotSchema = snapshot.getSchema(); final StructType prunedSchema = pruneSchema( fullSnapshotSchema, - inputRowSchema.getColumnsFilter() + Objects.requireNonNull(inputRowSchema, "inputRowSchema").getColumnsFilter() ); final ScanBuilder scanBuilder = snapshot.getScanBuilder(); diff --git a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java index 60af27fcd4d1..e73fdfcf4443 100644 --- a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java +++ b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java @@ -236,7 +236,9 @@ public void close() server.close(); } } else { - exec.shutdownNow(); + if (exec != null) { + exec.shutdownNow(); + } flush(); try { diff --git a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java index 8f72d3046ee7..5cf7f75832b3 100644 --- a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java +++ b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogram.java @@ -626,6 +626,8 @@ protected ApproximateHistogram foldRule(ApproximateHistogram h, @Nullable float[ // use preallocated arrays if passed if (mergedPositions == null) { mergedPositions = new float[this.size]; + } + if (mergedBins == null) { mergedBins = new long[this.size]; } diff --git a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java index 0d8fa70f7f18..c658f45c45ca 100644 --- a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java +++ b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java @@ -145,7 +145,7 @@ protected RecordSupplier setupReco @Override protected int getTaskGroupIdForPartition(KafkaTopicPartition partitionId) { - Integer taskCount = spec.getIoConfig().getTaskCount(); + final int taskCount = spec.getIoConfig().getTaskCount(); if (partitionId.isMultiTopicPartition()) { return Math.abs(31 * partitionId.topic().hashCode() + partitionId.partition()) % taskCount; } else { diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java index f45a950175e4..e92d3500edc6 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionMultiPhaseParallelIndexingTest.java @@ -352,18 +352,17 @@ private void assertHashedPartition( List segmentsInInterval = entry.getValue(); Assertions.assertEquals(expectedIntervalToNumSegments.get(interval).intValue(), segmentsInInterval.size()); for (DataSegment segment : segmentsInInterval) { - HashBasedNumberedShardSpec shardSpec = null; if (segment.isTombstone()) { Assertions.assertSame(TombstoneShardSpec.class, segment.getShardSpec().getClass()); } else { Assertions.assertSame(HashBasedNumberedShardSpec.class, segment.getShardSpec().getClass()); - shardSpec = (HashBasedNumberedShardSpec) segment.getShardSpec(); - Assertions.assertEquals(HashPartitionFunction.MURMUR3_32_ABS, shardSpec.getPartitionFunction()); } List results = querySegment(segment, ImmutableList.of("dim1", "dim2"), tempSegmentDir); if (segment.isTombstone()) { Assertions.assertTrue(results.isEmpty()); } else { + final HashBasedNumberedShardSpec shardSpec = (HashBasedNumberedShardSpec) segment.getShardSpec(); + Assertions.assertEquals(HashPartitionFunction.MURMUR3_32_ABS, shardSpec.getPartitionFunction()); final int hash = shardSpec.getPartitionFunction().hash( HashBasedNumberedShardSpec.serializeGroupKey( getObjectMapper(), diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java index 04670ba28a38..c1fd88464804 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskQueueScaleTest.java @@ -281,7 +281,7 @@ public ListenableFuture run(Task task) try { synchronized (knownTasks) { final TestTaskRunnerWorkItem item2 = knownTasks.get(task.getId()); - if (item2.getState() == RunnerTaskState.PENDING) { + if (item2 != null && item2.getState() == RunnerTaskState.PENDING) { knownTasks.put(task.getId(), item2.withState(RunnerTaskState.RUNNING)); } } @@ -292,7 +292,9 @@ public ListenableFuture run(Task task) final TestTaskRunnerWorkItem item2; synchronized (knownTasks) { item2 = knownTasks.get(task.getId()); - knownTasks.put(task.getId(), item2.withState(RunnerTaskState.NONE)); + if (item2 != null) { + knownTasks.put(task.getId(), item2.withState(RunnerTaskState.NONE)); + } } if (item2 != null) { item2.setResult(TaskStatus.success(task.getId())); diff --git a/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java b/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java index d285f1cd044e..9b558a1e1cc8 100644 --- a/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java +++ b/processing/src/main/java/org/apache/druid/hll/HyperLogLogCollector.java @@ -562,32 +562,31 @@ public boolean equals(Object o) return false; } - ByteBuffer otherBuffer = ((HyperLogLogCollector) o).storageBuffer; + final ByteBuffer otherBuffer = ((HyperLogLogCollector) o).storageBuffer; - if (storageBuffer != null ? false : otherBuffer != null) { - return false; - } - - if (storageBuffer == null && otherBuffer == null) { - return true; + if (storageBuffer == null || otherBuffer == null) { + return storageBuffer == otherBuffer; } final ByteBuffer denseStorageBuffer; if (storageBuffer.remaining() != getNumBytesForDenseStorage()) { - HyperLogLogCollector denseCollector = HyperLogLogCollector.makeCollector(storageBuffer.duplicate()); + final HyperLogLogCollector denseCollector = HyperLogLogCollector.makeCollector(storageBuffer.duplicate()); denseCollector.convertToDenseStorage(); denseStorageBuffer = denseCollector.storageBuffer; } else { denseStorageBuffer = storageBuffer; } + final ByteBuffer denseOtherBuffer; if (otherBuffer.remaining() != getNumBytesForDenseStorage()) { - HyperLogLogCollector otherCollector = HyperLogLogCollector.makeCollector(otherBuffer.duplicate()); + final HyperLogLogCollector otherCollector = HyperLogLogCollector.makeCollector(otherBuffer.duplicate()); otherCollector.convertToDenseStorage(); - otherBuffer = otherCollector.storageBuffer; + denseOtherBuffer = otherCollector.storageBuffer; + } else { + denseOtherBuffer = otherBuffer; } - return denseStorageBuffer.equals(otherBuffer); + return denseStorageBuffer.equals(denseOtherBuffer); } @Override diff --git a/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java b/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java index da78a0a74616..65489c3db093 100644 --- a/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java +++ b/processing/src/main/java/org/apache/druid/jackson/DruidDefaultSerializersModule.java @@ -40,6 +40,7 @@ import java.io.IOException; import java.nio.ByteOrder; +import java.util.Objects; /** * @@ -152,8 +153,8 @@ public void serialize(Yielder yielder, final JsonGenerator jgen, SerializerProvi } else { final Class clazz = o.getClass(); - if (serializerClass != clazz) { - serializer = JacksonUtils.getSerializer(provider, clazz); + if (serializer == null || serializerClass != clazz) { + serializer = Objects.requireNonNull(JacksonUtils.getSerializer(provider, clazz)); serializerClass = clazz; } diff --git a/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java b/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java index 1c1285c8b0c2..c9221d5a3576 100644 --- a/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java +++ b/processing/src/main/java/org/apache/druid/java/util/common/logger/Logger.java @@ -295,7 +295,7 @@ private void logException(BiConsumer fn, Throwable t, String fn.accept(message, t); } else { - if (message.isEmpty()) { + if (message == null || message.isEmpty()) { fn.accept(t.toString(), null); } else { fn.accept(StringUtils.nonStrictFormat("%s (%s)", message, t.toString()), null); diff --git a/processing/src/main/java/org/apache/druid/math/expr/Function.java b/processing/src/main/java/org/apache/druid/math/expr/Function.java index c43e8642f9ab..d2d9995d9c95 100644 --- a/processing/src/main/java/org/apache/druid/math/expr/Function.java +++ b/processing/src/main/java/org/apache/druid/math/expr/Function.java @@ -3268,13 +3268,15 @@ public String name() @Override public ExprEval apply(List args, Expr.ObjectBinding bindings) { - Long left = args.get(0).eval(bindings).asLong(); - Long right = args.get(1).eval(bindings).asLong(); - DateTimeZone timeZone = DateTimes.inferTzFromString(args.get(2).eval(bindings).asString()); + final ExprEval leftEval = args.get(0).eval(bindings); + final ExprEval rightEval = args.get(1).eval(bindings); + final DateTimeZone timeZone = DateTimes.inferTzFromString(args.get(2).eval(bindings).asString()); - if (left == null || right == null) { + if (leftEval.isNumericNull() || rightEval.isNumericNull()) { return ExprEval.ofLong(null); } else { + final long left = leftEval.asLong(); + final long right = rightEval.asLong(); return ExprEval.of(DateTimes.subMonths(right, left, timeZone)); } diff --git a/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java b/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java index a45c999b3c8c..270ab566814b 100644 --- a/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java +++ b/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java @@ -276,21 +276,15 @@ private Pair materializeCursorFactory(CursorFactory cursor sortColumns ); - final FrameWriter writer = frameWriterFactory.newFrameWriter(columnSelectorFactory); - for (; !cursor.isDoneOrInterrupted() && remainingRowsToSkip > 0; remainingRowsToSkip--) { - cursor.advance(); - } - for (; !cursor.isDoneOrInterrupted() && remainingRowsToFetch > 0; remainingRowsToFetch--) { - writer.addSelection(); - cursor.advance(); - } + try (final FrameWriter writer = frameWriterFactory.newFrameWriter(columnSelectorFactory)) { + for (; !cursor.isDoneOrInterrupted() && remainingRowsToSkip > 0; remainingRowsToSkip--) { + cursor.advance(); + } + for (; !cursor.isDoneOrInterrupted() && remainingRowsToFetch > 0; remainingRowsToFetch--) { + writer.addSelection(); + cursor.advance(); + } - if (writer == null) { - // This means that the accumulate was never called, which can only happen if we didn't have any cursors. - // We would only have zero cursors if we essentially didn't match anything, meaning that our RowsAndColumns - // should be completely empty. - return null; - } else { final byte[] bytes = writer.toByteArray(); return Pair.of(bytes, siggy.get()); } @@ -383,26 +377,28 @@ private Pair naiveMaterialize(RowsAndColumns rac) long remainingRowsToSkip = limit.getOffset(); long remainingRowsToFetch = limit.getLimitOrMax(); - final FrameWriter frameWriter = FrameWriters.makeColumnBasedFrameWriterFactory( - memFactory, - sigBob.build(), - Collections.emptyList() - ).newFrameWriter(selectorFactory); - - rowId.set(0); - for (; rowId.get() < numRows && remainingRowsToFetch > 0; rowId.incrementAndGet()) { - final int theId = rowId.get(); - if (rowsToSkip != null && rowsToSkip.get(theId)) { - continue; - } - if (remainingRowsToSkip > 0) { - remainingRowsToSkip--; - continue; + try ( + final FrameWriter frameWriter = FrameWriters.makeColumnBasedFrameWriterFactory( + memFactory, + sigBob.build(), + Collections.emptyList() + ).newFrameWriter(selectorFactory) + ) { + rowId.set(0); + for (; rowId.get() < numRows && remainingRowsToFetch > 0; rowId.incrementAndGet()) { + final int theId = rowId.get(); + if (rowsToSkip != null && rowsToSkip.get(theId)) { + continue; + } + if (remainingRowsToSkip > 0) { + remainingRowsToSkip--; + continue; + } + remainingRowsToFetch--; + frameWriter.addSelection(); } - remainingRowsToFetch--; - frameWriter.addSelection(); - } - return Pair.of(frameWriter.toByteArray(), sigBob.build()); + return Pair.of(frameWriter.toByteArray(), sigBob.build()); + } } } diff --git a/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java b/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java index 1fc09f57be6a..b4c4e83bbea4 100644 --- a/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java +++ b/processing/src/main/java/org/apache/druid/segment/generator/ColumnValueGenerator.java @@ -19,6 +19,7 @@ package org.apache.druid.segment.generator; +import com.google.common.base.Preconditions; import org.apache.commons.math3.distribution.AbstractIntegerDistribution; import org.apache.commons.math3.distribution.AbstractRealDistribution; import org.apache.commons.math3.distribution.EnumeratedDistribution; @@ -207,8 +208,18 @@ private void initDistribution() distribution = new UniformIntegerDistribution(schema.getStartInt(), schema.getEndInt()); break; case ENUMERATED: - for (int i = 0; i < enumeratedValues.size(); i++) { - probabilities.add(new Pair<>(enumeratedValues.get(i), enumeratedProbabilities.get(i))); + final List nonNullEnumeratedValues = + Preconditions.checkNotNull(enumeratedValues, "enumeratedValues"); + final List nonNullEnumeratedProbabilities = + Preconditions.checkNotNull(enumeratedProbabilities, "enumeratedProbabilities"); + Preconditions.checkArgument( + nonNullEnumeratedValues.size() == nonNullEnumeratedProbabilities.size(), + "enumeratedValues size[%s] must match enumeratedProbabilities size[%s]", + nonNullEnumeratedValues.size(), + nonNullEnumeratedProbabilities.size() + ); + for (int i = 0; i < nonNullEnumeratedValues.size(); i++) { + probabilities.add(new Pair<>(nonNullEnumeratedValues.get(i), nonNullEnumeratedProbabilities.get(i))); } distribution = new EnumeratedTreeDistribution<>(probabilities); break; diff --git a/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java b/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java index 6f1d87a8c35e..13b4b2b63a48 100644 --- a/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java +++ b/processing/src/test/java/org/apache/druid/java/util/common/parsers/JSONFlattenerMakerTest.java @@ -67,11 +67,11 @@ public void testNumbers() throws JsonProcessingException { JsonNode node; Object result; - Integer i1 = 123; + final int i1 = 123; node = OBJECT_MAPPER.readTree(OBJECT_MAPPER.writeValueAsString(i1)); Assertions.assertTrue(node.isInt()); result = FLATTENER_MAKER.finalizeConversionForMap(node); - Assertions.assertEquals(i1.longValue(), result); + Assertions.assertEquals((long) i1, result); Long l1 = 1L + Integer.MAX_VALUE; node = OBJECT_MAPPER.readTree(OBJECT_MAPPER.writeValueAsString(l1)); diff --git a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java index 581707b4be00..a5d83f6a0a1f 100644 --- a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java +++ b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/first/StringFirstBufferAggregatorTest.java @@ -48,7 +48,7 @@ public void testBufferAggregate() { final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 1526725900L, 1526725000L}; final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(strings); @@ -85,7 +85,7 @@ public void testBufferAggregateWithFoldCheck() { final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 1526725900L, 1526725000L}; final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(strings); @@ -123,7 +123,7 @@ public void testNullBufferAggregate() final long[] timestamps = {2222L, 1111L, 3333L, 4444L, 5555L}; final String[] strings = {null, "AAAA", "BBBB", "DDDD", "EEEE"}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(strings); @@ -162,7 +162,7 @@ public void testNoStringValue() final long[] timestamps = {1526724000L, 1526724600L}; final Double[] doubles = {null, 2.00}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(doubles); diff --git a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java index 3f1e66f802a5..5f38c623982e 100644 --- a/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java +++ b/processing/src/test/java/org/apache/druid/query/aggregation/firstlast/last/StringLastBufferAggregatorTest.java @@ -49,7 +49,7 @@ public void testBufferAggregate() final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 1526725900L, 1526725000L}; final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(strings); @@ -87,7 +87,7 @@ public void testBufferAggregateWithFoldCheck() { final long[] timestamps = {1526724600L, 1526724700L, 1526724800L, 1526725900L, 1526725000L}; final String[] strings = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE"}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(strings); @@ -125,7 +125,7 @@ public void testNullBufferAggregate() final long[] timestamps = {1111L, 2222L, 6666L, 4444L, 5555L}; final String[] strings = {"CCCC", "AAAA", "BBBB", null, "EEEE"}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(strings); @@ -164,7 +164,7 @@ public void testNonStringValue() final long[] timestamps = {1526724000L, 1526724600L}; final Double[] doubles = {null, 2.00}; - Integer maxStringBytes = 1024; + final int maxStringBytes = 1024; TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps); TestObjectColumnSelector objectColumnSelector = new TestObjectColumnSelector<>(doubles); diff --git a/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java b/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java index a92dfcb61833..e718f07c781a 100644 --- a/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java +++ b/processing/src/test/java/org/apache/druid/segment/data/BenchmarkIndexibleWrites.java @@ -128,7 +128,7 @@ public void clear() reference.set((V[]) new Object[initSize]); } - private static Boolean wasCopying(Long val) + private static boolean wasCopying(long val) { return (val & 1L) > 0; } @@ -137,12 +137,13 @@ private static Boolean wasCopying(Long val) public void set(Integer index, V object) { ensureCapacity(index + 1); - Long pre, post; + long pre; + long post; do { pre = resizeCount.get(); reference.get()[index] = object; post = resizeCount.get(); - } while (wasCopying(pre) || wasCopying(post) || (!pre.equals(post))); + } while (wasCopying(pre) || wasCopying(post) || pre != post); } private final Object resizeMutex = new Object(); @@ -192,7 +193,7 @@ public void testConcurrentWrites() throws ExecutionException, InterruptedExcepti final AtomicInteger index = new AtomicInteger(0); List> futures = new ArrayList<>(); - final Integer loops = totalIndexSize / concurrentThreads; + final int loops = totalIndexSize / concurrentThreads; for (int i = 0; i < concurrentThreads; ++i) { futures.add( @@ -244,7 +245,7 @@ public void testConcurrentReads() throws ExecutionException, InterruptedExceptio final AtomicInteger queryableIndex = new AtomicInteger(0); List> futures = new ArrayList<>(); - final Integer loops = totalIndexSize / concurrentThreads; + final int loops = totalIndexSize / concurrentThreads; final AtomicBoolean done = new AtomicBoolean(false); diff --git a/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java b/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java index 58c49b318870..1a440f9a3bb8 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/PredicateValueMatcherFactoryTest.java @@ -158,26 +158,26 @@ public void testDoubleProcessorNotMatchingValue() @Test public void testNumberProcessorMatchingValue() { - Double num = 2.; + final double num = 2.; final TestColumnValueSelector columnValueSelector = TestColumnValueSelector.of( Number.class, ImmutableList.of(new Number() { @Override public int intValue() { - return num.intValue(); + return (int) num; } @Override public long longValue() { - return num.longValue(); + return (long) num; } @Override public float floatValue() { - return num.floatValue(); + return (float) num; } @Override @@ -195,26 +195,26 @@ public double doubleValue() @Test public void testNumberProcessorNotMatchingValue() { - Double num = 2.; + final double num = 2.; final TestColumnValueSelector columnValueSelector = TestColumnValueSelector.of( Double.class, ImmutableList.of(new Number() { @Override public int intValue() { - return num.intValue(); + return (int) num; } @Override public long longValue() { - return num.longValue(); + return (long) num; } @Override public float floatValue() { - return num.floatValue(); + return (float) num; } @Override diff --git a/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java b/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java index 0a4e490af3bb..973fbe4e1a31 100644 --- a/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java +++ b/processing/src/test/java/org/apache/druid/segment/generator/DataGeneratorTest.java @@ -298,6 +298,27 @@ public void testEnumerated() tracker.assertTotalRowSize("dimA", 10000); } + @Test + public void testEnumeratedRejectsMismatchedValuesAndProbabilities() + { + final GeneratorColumnSchema schema = GeneratorColumnSchema.makeEnumerated( + "dimA", + ValueType.STRING, + false, + 1, + null, + Arrays.asList("Hello", "World"), + Collections.singletonList(1.0) + ); + + final IllegalArgumentException exception = Assertions.assertThrows( + IllegalArgumentException.class, + () -> schema.makeGenerator(9999) + ); + Assertions.assertTrue(exception.getMessage().contains("enumeratedValues size[2]")); + Assertions.assertTrue(exception.getMessage().contains("enumeratedProbabilities size[1]")); + } + @Test public void testNormal() { diff --git a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java index 26a45eaae251..259450f69473 100644 --- a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java +++ b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java @@ -371,15 +371,15 @@ public void doesNotLoadIfPresent() @Test public void evictsLeastRecentlyUsed() { - Long start = 1L; - Long next = start + SIZE; + final long start = 1L; + final long next = start + SIZE; for (long i = start; i < next; i++) { - Long key = i; - Assertions.assertEquals(key, target.getAndLoadIfAbsent(key)); + final long key = i; + Assertions.assertEquals(key, target.getAndLoadIfAbsent(key).longValue()); } - Assertions.assertEquals(next, target.getAndLoadIfAbsent(next)); + Assertions.assertEquals(next, target.getAndLoadIfAbsent(next).longValue()); Assertions.assertNull(target.get(start)); Assertions.assertEquals(SIZE + 1, counter.longValue()); diff --git a/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java b/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java index 00f527955f89..91d38b1d6703 100644 --- a/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java +++ b/processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java @@ -62,8 +62,8 @@ public void test_closeAll_list_quiet() throws IOException @Test public void test_closeAll_array_loud() { - final Exception e = Assertions.assertThrows( - Exception.class, + final IOException e = Assertions.assertThrows( + IOException.class, () -> CloseableUtils.closeAll( quietCloseable, null, @@ -75,9 +75,6 @@ public void test_closeAll_array_loud() assertClosed(quietCloseable, ioExceptionCloseable, quietCloseable2, runtimeExceptionCloseable); - // First exception - Assertions.assertInstanceOf(IOException.class, e); - // Second exception Assertions.assertEquals(1, e.getSuppressed().length); Assertions.assertInstanceOf(IllegalArgumentException.class, e.getSuppressed()[0]); @@ -86,8 +83,8 @@ public void test_closeAll_array_loud() @Test public void test_closeAll_list_loud() { - final Exception e = Assertions.assertThrows( - Exception.class, + final IOException e = Assertions.assertThrows( + IOException.class, () -> CloseableUtils.closeAll( Arrays.asList( quietCloseable, @@ -101,9 +98,6 @@ public void test_closeAll_list_loud() assertClosed(quietCloseable, ioExceptionCloseable, quietCloseable2, runtimeExceptionCloseable); - // First exception - Assertions.assertInstanceOf(IOException.class, e); - // Second exception Assertions.assertEquals(1, e.getSuppressed().length); Assertions.assertInstanceOf(IllegalArgumentException.class, e.getSuppressed()[0]); diff --git a/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java b/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java index 91fd583d4dbc..0b54bb7257b4 100644 --- a/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java +++ b/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java @@ -2259,13 +2259,13 @@ public void mount(StorageLocation mountLocation) throws SegmentLoadingException log.makeAlert( e, "Failed to load segment in current location [%s], try next location if any", - location.getPath().getAbsolutePath() - ).addData("location", location.getPath().getAbsolutePath()).emit(); + mountLocation.getPath().getAbsolutePath() + ).addData("location", mountLocation.getPath().getAbsolutePath()).emit(); throw new SegmentLoadingException( "Failed to load segment[%s] in reserved location[%s]", dataSegment.getId(), - location.getPath().getAbsolutePath() + mountLocation.getPath().getAbsolutePath() ); } finally { diff --git a/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java b/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java index dec2cdf29476..c99bd3e7bb22 100644 --- a/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java +++ b/server/src/test/java/org/apache/druid/rpc/MockServiceClient.java @@ -34,6 +34,7 @@ import java.util.ArrayDeque; import java.util.Map; +import java.util.Objects; import java.util.Queue; /** @@ -50,11 +51,14 @@ public ListenableFuture asyncRequest( final HttpResponseHandler handler ) { - final Expectation expectation = expectations.poll(); + final Expectation expectation = Objects.requireNonNull( + expectations.poll(), + "No expectation configured for the next request" + ); requestNumber++; Assertions.assertEquals( - expectation == null ? null : expectation.request, + expectation.request, requestBuilder, "request[" + requestNumber + "]" ); diff --git a/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java index b042ad69bd9e..4cb83242da4d 100644 --- a/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java +++ b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtils.java @@ -60,13 +60,17 @@ private static boolean checkEquals( * test code * @param expected expected list * @param actual actual list - * @return */ - public static boolean assertEquals(List expected, List actual) + public static void assertEquals( + @Nullable List expected, + @Nullable List actual + ) { if (expected == null) { - return actual == null; + Assertions.assertNull(actual); + return; } + Assertions.assertNotNull(actual); Assertions.assertEquals(expected.size(), actual.size(), "expected and actual ImmutableDruidDataSource lists should be of equal size"); @@ -77,7 +81,6 @@ public static boolean assertEquals(List expected, List "ImmutableDruidDataSource's equalsForTesting()" + " method"); } } - return true; } private static boolean contains(ImmutableDruidDataSource expected, List actualList) diff --git a/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtilsTest.java b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtilsTest.java new file mode 100644 index 000000000000..e924e9f54903 --- /dev/null +++ b/server/src/test/java/org/apache/druid/test/utils/ImmutableDruidDataSourceTestUtilsTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.test.utils; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +public class ImmutableDruidDataSourceTestUtilsTest +{ + @Test + public void testListAssertEqualsRejectsNullActual() + { + Assertions.assertThrows( + AssertionError.class, + () -> ImmutableDruidDataSourceTestUtils.assertEquals(Collections.emptyList(), null) + ); + } + + @Test + public void testListAssertEqualsRejectsNullExpected() + { + Assertions.assertThrows( + AssertionError.class, + () -> ImmutableDruidDataSourceTestUtils.assertEquals(null, Collections.emptyList()) + ); + } +} diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java index 73209a76a987..902132f1812c 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java @@ -254,20 +254,21 @@ public Aggregation toDruidAggregation( case 1: theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, fieldName, null, outputType, null, true); break; - case 2: - Integer maxStringBytes = RexLiteral.intValue(rexNodes.get(1)); // added not null check at the function + case 2: { + final int maxStringBytes = RexLiteral.intValue(rexNodes.get(1)); theAggFactory = aggregatorType.createAggregatorFactory( aggregatorName, fieldName, null, outputType, - maxStringBytes.intValue(), + maxStringBytes, true ); break; - case 3: - maxStringBytes = RexLiteral.intValue(rexNodes.get(1)); // added not null check at the function for rexNode 1,2 - boolean aggregateMultipleValues = RexLiteral.booleanValue(rexNodes.get(2)); + } + case 3: { + final int maxStringBytes = RexLiteral.intValue(rexNodes.get(1)); + final boolean aggregateMultipleValues = RexLiteral.booleanValue(rexNodes.get(2)); theAggFactory = aggregatorType.createAggregatorFactory( aggregatorName, fieldName, @@ -277,6 +278,7 @@ public Aggregation toDruidAggregation( aggregateMultipleValues ); break; + } default: throw InvalidSqlInput.exception( "Function [%s] expects 1 or 2 or 3 arguments but found [%s]",