Skip to content

Commit

Permalink
apacheGH-39330: [Java][CI] Fix or suppress spurious errorprone warnin…
Browse files Browse the repository at this point in the history
…gs (apache#39529)

### Rationale for this change

This PR fixes the warnings generated by the errorprone library. 

### What changes are included in this PR?

Updating the code to remove warnings. 

Covered modules
- [x] algorithm
- [x] compression
- [x] flight
- [x] tools
- [x] vector 

### Are these changes tested?

Tested by existing test cases.

### Are there any user-facing changes?

No
* Closes: apache#39330

Lead-authored-by: Vibhatha Lakmal Abeykoon <vibhatha@gmail.com>
Co-authored-by: vibhatha <vibhatha@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
2 people authored and thisisnic committed Mar 8, 2024
1 parent ac7d648 commit c607273
Show file tree
Hide file tree
Showing 189 changed files with 1,189 additions and 1,031 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

import org.apache.arrow.algorithm.sort.VectorValueComparator;
import org.apache.arrow.vector.ValueVector;
Expand Down Expand Up @@ -95,7 +96,7 @@ public int search(V keyVector, int keyIndex) throws ExecutionException, Interrup
final int valueCount = vector.getValueCount();
for (int i = 0; i < numThreads; i++) {
final int tid = i;
threadPool.submit(() -> {
Future<?> unused = threadPool.submit(() -> {
// convert to long to avoid overflow
int start = (int) (((long) valueCount) * tid / numThreads);
int end = (int) ((long) valueCount) * (tid + 1) / numThreads;
Expand Down Expand Up @@ -153,7 +154,7 @@ public int search(
final int valueCount = vector.getValueCount();
for (int i = 0; i < numThreads; i++) {
final int tid = i;
threadPool.submit(() -> {
Future<?> unused = threadPool.submit(() -> {
// convert to long to avoid overflow
int start = (int) (((long) valueCount) * tid / numThreads);
int end = (int) ((long) valueCount) * (tid + 1) / numThreads;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator<V> co
"Expected capacity %s, actual capacity %s",
(srcVector.getValueCount() + 7) / 8, dstValidityBuffer.capacity());
Preconditions.checkArgument(
dstValueBuffer.capacity() >= srcVector.getValueCount() * srcVector.getTypeWidth(),
dstValueBuffer.capacity() >= srcVector.getValueCount() * ((long) srcVector.getTypeWidth()),
"Not enough capacity for the data buffer of the dst vector. " +
"Expected capacity %s, actual capacity %s",
srcVector.getValueCount() * srcVector.getTypeWidth(), dstValueBuffer.capacity());
Expand All @@ -73,8 +73,8 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator<V> co
} else {
BitVectorHelper.setBit(dstValidityBuffer, dstIndex);
MemoryUtil.UNSAFE.copyMemory(
srcValueBuffer.memoryAddress() + srcIndex * valueWidth,
dstValueBuffer.memoryAddress() + dstIndex * valueWidth,
srcValueBuffer.memoryAddress() + srcIndex * ((long) valueWidth),
dstValueBuffer.memoryAddress() + dstIndex * ((long) valueWidth),
valueWidth);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator<V> co
"Expected capacity %s, actual capacity %s",
(srcVector.getValueCount() + 7) / 8, dstValidityBuffer.capacity());
Preconditions.checkArgument(
dstOffsetBuffer.capacity() >= (srcVector.getValueCount() + 1) * BaseVariableWidthVector.OFFSET_WIDTH,
dstOffsetBuffer.capacity() >= (srcVector.getValueCount() + 1) * ((long) BaseVariableWidthVector.OFFSET_WIDTH),
"Not enough capacity for the offset buffer of the dst vector. " +
"Expected capacity %s, actual capacity %s",
(srcVector.getValueCount() + 1) * BaseVariableWidthVector.OFFSET_WIDTH, dstOffsetBuffer.capacity());
long dataSize = srcVector.getOffsetBuffer().getInt(
srcVector.getValueCount() * BaseVariableWidthVector.OFFSET_WIDTH);
srcVector.getValueCount() * ((long) BaseVariableWidthVector.OFFSET_WIDTH));
Preconditions.checkArgument(
dstValueBuffer.capacity() >= dataSize, "No enough capacity for the data buffer of the dst vector. " +
"Expected capacity %s, actual capacity %s", dataSize, dstValueBuffer.capacity());
Expand All @@ -77,15 +77,16 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator<V> co
BitVectorHelper.unsetBit(dstValidityBuffer, dstIndex);
} else {
BitVectorHelper.setBit(dstValidityBuffer, dstIndex);
int srcOffset = srcOffsetBuffer.getInt(srcIndex * BaseVariableWidthVector.OFFSET_WIDTH);
int valueLength = srcOffsetBuffer.getInt((srcIndex + 1) * BaseVariableWidthVector.OFFSET_WIDTH) - srcOffset;
int srcOffset = srcOffsetBuffer.getInt(srcIndex * ((long) BaseVariableWidthVector.OFFSET_WIDTH));
int valueLength =
srcOffsetBuffer.getInt((srcIndex + 1) * ((long) BaseVariableWidthVector.OFFSET_WIDTH)) - srcOffset;
MemoryUtil.UNSAFE.copyMemory(
srcValueBuffer.memoryAddress() + srcOffset,
dstValueBuffer.memoryAddress() + dstOffset,
valueLength);
dstOffset += valueLength;
}
dstOffsetBuffer.setInt((dstIndex + 1) * BaseVariableWidthVector.OFFSET_WIDTH, dstOffset);
dstOffsetBuffer.setInt((dstIndex + 1) * ((long) BaseVariableWidthVector.OFFSET_WIDTH), dstOffset);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import java.nio.charset.StandardCharsets;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
Expand Down Expand Up @@ -107,7 +109,7 @@ public void testDeduplicateVariableWidth() {
for (int i = 0; i < VECTOR_LENGTH; i++) {
String str = String.valueOf(i * i);
for (int j = 0; j < REPETITION_COUNT; j++) {
origVec.set(i * REPETITION_COUNT + j, str.getBytes());
origVec.set(i * REPETITION_COUNT + j, str.getBytes(StandardCharsets.UTF_8));
}
}

Expand All @@ -120,7 +122,7 @@ public void testDeduplicateVariableWidth() {
assertEquals(VECTOR_LENGTH, dedupVec.getValueCount());

for (int i = 0; i < VECTOR_LENGTH; i++) {
assertArrayEquals(String.valueOf(i * i).getBytes(), dedupVec.get(i));
assertArrayEquals(String.valueOf(i * i).getBytes(StandardCharsets.UTF_8), dedupVec.get(i));
}

DeduplicationUtils.populateRunLengths(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import java.nio.charset.StandardCharsets;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.IntVector;
Expand Down Expand Up @@ -104,20 +106,20 @@ public void testDeduplicateVariableWidth() {
for (int i = 0; i < VECTOR_LENGTH; i++) {
String str = String.valueOf(i * i);
for (int j = 0; j < REPETITION_COUNT; j++) {
origVec.set(i * REPETITION_COUNT + j, str.getBytes());
origVec.set(i * REPETITION_COUNT + j, str.getBytes(StandardCharsets.UTF_8));
}
}

int distinctCount = deduplicator.getRunCount();
assertEquals(VECTOR_LENGTH, distinctCount);

dedupVec.allocateNew(distinctCount * 10, distinctCount);
dedupVec.allocateNew(distinctCount * 10L, distinctCount);

deduplicator.populateDeduplicatedValues(dedupVec);
assertEquals(VECTOR_LENGTH, dedupVec.getValueCount());

for (int i = 0; i < VECTOR_LENGTH; i++) {
assertArrayEquals(String.valueOf(i * i).getBytes(), dedupVec.get(i));
assertArrayEquals(String.valueOf(i * i).getBytes(StandardCharsets.UTF_8), dedupVec.get(i));
}

deduplicator.populateRunLengths(lengthVec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.IntVector;
Expand Down Expand Up @@ -57,16 +60,16 @@ public void testBuildVariableWidthDictionaryWithNull() {
dictionary.allocateNew();

// fill data
vec.set(0, "hello".getBytes());
vec.set(1, "abc".getBytes());
vec.set(0, "hello".getBytes(StandardCharsets.UTF_8));
vec.set(1, "abc".getBytes(StandardCharsets.UTF_8));
vec.setNull(2);
vec.set(3, "world".getBytes());
vec.set(4, "12".getBytes());
vec.set(5, "dictionary".getBytes());
vec.set(3, "world".getBytes(StandardCharsets.UTF_8));
vec.set(4, "12".getBytes(StandardCharsets.UTF_8));
vec.set(5, "dictionary".getBytes(StandardCharsets.UTF_8));
vec.setNull(6);
vec.set(7, "hello".getBytes());
vec.set(8, "good".getBytes());
vec.set(9, "abc".getBytes());
vec.set(7, "hello".getBytes(StandardCharsets.UTF_8));
vec.set(8, "good".getBytes(StandardCharsets.UTF_8));
vec.set(9, "abc".getBytes(StandardCharsets.UTF_8));

HashTableBasedDictionaryBuilder<VarCharVector> dictionaryBuilder =
new HashTableBasedDictionaryBuilder<>(dictionary, true);
Expand All @@ -76,13 +79,13 @@ public void testBuildVariableWidthDictionaryWithNull() {
assertEquals(7, result);
assertEquals(7, dictionary.getValueCount());

assertEquals("hello", new String(dictionary.get(0)));
assertEquals("abc", new String(dictionary.get(1)));
assertEquals("hello", new String(Objects.requireNonNull(dictionary.get(0)), StandardCharsets.UTF_8));
assertEquals("abc", new String(Objects.requireNonNull(dictionary.get(1)), StandardCharsets.UTF_8));
assertNull(dictionary.get(2));
assertEquals("world", new String(dictionary.get(3)));
assertEquals("12", new String(dictionary.get(4)));
assertEquals("dictionary", new String(dictionary.get(5)));
assertEquals("good", new String(dictionary.get(6)));
assertEquals("world", new String(Objects.requireNonNull(dictionary.get(3)), StandardCharsets.UTF_8));
assertEquals("12", new String(Objects.requireNonNull(dictionary.get(4)), StandardCharsets.UTF_8));
assertEquals("dictionary", new String(Objects.requireNonNull(dictionary.get(5)), StandardCharsets.UTF_8));
assertEquals("good", new String(Objects.requireNonNull(dictionary.get(6)), StandardCharsets.UTF_8));
}
}

Expand All @@ -97,16 +100,16 @@ public void testBuildVariableWidthDictionaryWithoutNull() {
dictionary.allocateNew();

// fill data
vec.set(0, "hello".getBytes());
vec.set(1, "abc".getBytes());
vec.set(0, "hello".getBytes(StandardCharsets.UTF_8));
vec.set(1, "abc".getBytes(StandardCharsets.UTF_8));
vec.setNull(2);
vec.set(3, "world".getBytes());
vec.set(4, "12".getBytes());
vec.set(5, "dictionary".getBytes());
vec.set(3, "world".getBytes(StandardCharsets.UTF_8));
vec.set(4, "12".getBytes(StandardCharsets.UTF_8));
vec.set(5, "dictionary".getBytes(StandardCharsets.UTF_8));
vec.setNull(6);
vec.set(7, "hello".getBytes());
vec.set(8, "good".getBytes());
vec.set(9, "abc".getBytes());
vec.set(7, "hello".getBytes(StandardCharsets.UTF_8));
vec.set(8, "good".getBytes(StandardCharsets.UTF_8));
vec.set(9, "abc".getBytes(StandardCharsets.UTF_8));

HashTableBasedDictionaryBuilder<VarCharVector> dictionaryBuilder =
new HashTableBasedDictionaryBuilder<>(dictionary, false);
Expand All @@ -116,12 +119,12 @@ public void testBuildVariableWidthDictionaryWithoutNull() {
assertEquals(6, result);
assertEquals(6, dictionary.getValueCount());

assertEquals("hello", new String(dictionary.get(0)));
assertEquals("abc", new String(dictionary.get(1)));
assertEquals("world", new String(dictionary.get(2)));
assertEquals("12", new String(dictionary.get(3)));
assertEquals("dictionary", new String(dictionary.get(4)));
assertEquals("good", new String(dictionary.get(5)));
assertEquals("hello", new String(Objects.requireNonNull(dictionary.get(0)), StandardCharsets.UTF_8));
assertEquals("abc", new String(Objects.requireNonNull(dictionary.get(1)), StandardCharsets.UTF_8));
assertEquals("world", new String(Objects.requireNonNull(dictionary.get(2)), StandardCharsets.UTF_8));
assertEquals("12", new String(Objects.requireNonNull(dictionary.get(3)), StandardCharsets.UTF_8));
assertEquals("dictionary", new String(Objects.requireNonNull(dictionary.get(4)), StandardCharsets.UTF_8));
assertEquals("good", new String(Objects.requireNonNull(dictionary.get(5)), StandardCharsets.UTF_8));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public void testEncodeAndDecode() {
dictionary.allocateNew();
for (int i = 0; i < DICTIONARY_LENGTH; i++) {
// encode "i" as i
dictionary.setSafe(i, String.valueOf(i).getBytes());
dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8));
}
dictionary.setValueCount(DICTIONARY_LENGTH);

// set up raw vector
rawVector.allocateNew(10 * VECTOR_LENGTH, VECTOR_LENGTH);
for (int i = 0; i < VECTOR_LENGTH; i++) {
int val = (random.nextInt() & Integer.MAX_VALUE) % DICTIONARY_LENGTH;
rawVector.set(i, String.valueOf(val).getBytes());
rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8));
}
rawVector.setValueCount(VECTOR_LENGTH);

Expand All @@ -98,7 +98,7 @@ public void testEncodeAndDecode() {
// verify encoding results
assertEquals(rawVector.getValueCount(), encodedVector.getValueCount());
for (int i = 0; i < VECTOR_LENGTH; i++) {
assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes());
assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8));
}

// perform decoding
Expand All @@ -108,7 +108,8 @@ public void testEncodeAndDecode() {
// verify decoding results
assertEquals(encodedVector.getValueCount(), decodedVector.getValueCount());
for (int i = 0; i < VECTOR_LENGTH; i++) {
assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(), decodedVector.get(i));
assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8),
decodedVector.get(i));
}
}
}
Expand All @@ -126,7 +127,7 @@ public void testEncodeAndDecodeWithNull() {
dictionary.setNull(0);
for (int i = 1; i < DICTIONARY_LENGTH; i++) {
// encode "i" as i
dictionary.setSafe(i, String.valueOf(i).getBytes());
dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8));
}
dictionary.setValueCount(DICTIONARY_LENGTH);

Expand All @@ -137,7 +138,7 @@ public void testEncodeAndDecodeWithNull() {
rawVector.setNull(i);
} else {
int val = (random.nextInt() & Integer.MAX_VALUE) % (DICTIONARY_LENGTH - 1) + 1;
rawVector.set(i, String.valueOf(val).getBytes());
rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8));
}
}
rawVector.setValueCount(VECTOR_LENGTH);
Expand All @@ -155,7 +156,7 @@ public void testEncodeAndDecodeWithNull() {
if (i % 10 == 0) {
assertEquals(0, encodedVector.get(i));
} else {
assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes());
assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8));
}
}

Expand All @@ -168,7 +169,8 @@ public void testEncodeAndDecodeWithNull() {
if (i % 10 == 0) {
assertTrue(decodedVector.isNull(i));
} else {
assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(), decodedVector.get(i));
assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8),
decodedVector.get(i));
}
}
}
Expand All @@ -185,7 +187,7 @@ public void testEncodeNullWithoutNullInDictionary() {
dictionary.allocateNew();
for (int i = 0; i < DICTIONARY_LENGTH; i++) {
// encode "i" as i
dictionary.setSafe(i, String.valueOf(i).getBytes());
dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8));
}
dictionary.setValueCount(DICTIONARY_LENGTH);

Expand Down
Loading

0 comments on commit c607273

Please sign in to comment.