From ec285cd6bf5ca60e9dc7568c612406d8120882e1 Mon Sep 17 00:00:00 2001 From: Vibhatha Lakmal Abeykoon Date: Mon, 8 Jan 2024 16:36:48 +0530 Subject: [PATCH 01/23] fixing warnings v1 --- java/flight/flight-core/pom.xml | 4 +++ .../org/apache/arrow/flight/PollInfo.java | 6 ++-- .../arrow/flight/TestBasicOperation.java | 15 +++++---- .../arrow/flight/TestDictionaryUtils.java | 11 ++++--- .../arrow/flight/TestFlightService.java | 5 +-- .../apache/arrow/flight/TestLargeMessage.java | 3 +- .../arrow/flight/TestServerMiddleware.java | 32 +++++++++---------- .../java/org/apache/arrow/flight/TestTls.java | 2 +- .../flight/client/TestCookieHandling.java | 1 + .../apache/arrow/flight/perf/TestPerf.java | 4 +-- 10 files changed, 46 insertions(+), 37 deletions(-) diff --git a/java/flight/flight-core/pom.xml b/java/flight/flight-core/pom.xml index b7624d7748e..0346172f610 100644 --- a/java/flight/flight-core/pom.xml +++ b/java/flight/flight-core/pom.xml @@ -86,6 +86,10 @@ com.google.protobuf protobuf-java + + com.google.protobuf + protobuf-java-util + io.grpc grpc-api diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/PollInfo.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/PollInfo.java index 2bb3c6db695..59150d8814c 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/PollInfo.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/PollInfo.java @@ -27,6 +27,7 @@ import org.apache.arrow.flight.impl.Flight; import com.google.protobuf.Timestamp; +import com.google.protobuf.util.Timestamps; /** * A POJO representation of the execution of a long-running query. @@ -57,7 +58,7 @@ public PollInfo(FlightInfo flightInfo, FlightDescriptor flightDescriptor, Double this.flightDescriptor = flt.hasFlightDescriptor() ? new FlightDescriptor(flt.getFlightDescriptor()) : null; this.progress = flt.hasProgress() ? flt.getProgress() : null; this.expirationTime = flt.hasExpirationTime() ? - Instant.ofEpochSecond(flt.getExpirationTime().getSeconds(), flt.getExpirationTime().getNanos()) : + Instant.ofEpochSecond(flt.getExpirationTime().getSeconds(), Timestamps.toNanos(flt.getExpirationTime())) : null; } @@ -133,7 +134,8 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + + if (!(o instanceof PollInfo)) { return false; } PollInfo pollInfo = (PollInfo) o; diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java index 41b3a4693e5..0335c73f234 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java @@ -17,6 +17,7 @@ package org.apache.arrow.flight; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST; import static org.apache.arrow.flight.Location.forGrpcInsecure; @@ -28,7 +29,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.channels.Channels; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -114,11 +114,11 @@ public void roundTripInfo() throws Exception { Field.nullable("b", new ArrowType.FixedSizeBinary(32)) ), metadata); final FlightInfo info1 = FlightInfo.builder(schema, FlightDescriptor.path(), Collections.emptyList()) - .setAppMetadata("foo".getBytes()).build(); + .setAppMetadata("foo".getBytes(UTF_8)).build(); final FlightInfo info2 = new FlightInfo(schema, FlightDescriptor.command(new byte[2]), Collections.singletonList( FlightEndpoint.builder(new Ticket(new byte[10]), Location.forGrpcDomainSocket("/tmp/test.sock")) - .setAppMetadata("bar".getBytes()).build() + .setAppMetadata("bar".getBytes(UTF_8)).build() ), 200, 500); final FlightInfo info3 = new FlightInfo(schema, FlightDescriptor.path("a", "b"), Arrays.asList(new FlightEndpoint( @@ -150,7 +150,7 @@ public void roundTripInfo() throws Exception { @Test public void roundTripDescriptor() throws Exception { - final FlightDescriptor cmd = FlightDescriptor.command("test command".getBytes(StandardCharsets.UTF_8)); + final FlightDescriptor cmd = FlightDescriptor.command("test command".getBytes(UTF_8)); Assertions.assertEquals(cmd, FlightDescriptor.deserialize(cmd.serialize())); final FlightDescriptor path = FlightDescriptor.path("foo", "bar", "test.arrow"); Assertions.assertEquals(path, FlightDescriptor.deserialize(path.serialize())); @@ -160,7 +160,7 @@ public void roundTripDescriptor() throws Exception { public void getDescriptors() throws Exception { test(c -> { int count = 0; - for (FlightInfo i : c.listFlights(Criteria.ALL)) { + for (FlightInfo unused : c.listFlights(Criteria.ALL)) { count += 1; } Assertions.assertEquals(1, count); @@ -171,7 +171,8 @@ public void getDescriptors() throws Exception { public void getDescriptorsWithCriteria() throws Exception { test(c -> { int count = 0; - for (FlightInfo i : c.listFlights(new Criteria(new byte[]{1}))) { + for (FlightInfo unused : c.listFlights(new Criteria(new byte[]{1}))) { + count += 1; } Assertions.assertEquals(0, count); @@ -460,7 +461,7 @@ public void testGrpcTlsLocation() throws Exception { * An example FlightProducer for test purposes. */ public static class Producer implements FlightProducer, AutoCloseable { - static final byte[] TICKET_LARGE_BATCH = "large-batch".getBytes(StandardCharsets.UTF_8); + static final byte[] TICKET_LARGE_BATCH = "large-batch".getBytes(UTF_8); private final BufferAllocator allocator; diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java index b3a716ab3ce..7aa8b9bd182 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java @@ -17,9 +17,6 @@ package org.apache.arrow.flight; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.TreeSet; import org.apache.arrow.memory.BufferAllocator; @@ -36,6 +33,10 @@ import com.google.common.collect.ImmutableList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + /** * Test cases for {@link DictionaryUtils}. */ @@ -54,7 +55,7 @@ public void testReuseSchema() { Schema newSchema = DictionaryUtils.generateSchema(schema, null, new TreeSet<>()); // assert that no new schema is created. - assertTrue(schema == newSchema); + assertSame(schema, newSchema); } @Test @@ -78,7 +79,7 @@ public void testCreateSchema() { Schema newSchema = DictionaryUtils.generateSchema(schema, dictProvider, dictionaryUsed); // assert that a new schema is created. - assertTrue(schema != newSchema); + assertNotEquals(schema, newSchema); // assert the column is converted as expected ArrowType newColType = newSchema.getFields().get(0).getType(); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java index 0e4669f29ce..803d4086570 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java @@ -17,6 +17,7 @@ package org.apache.arrow.flight; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST; import static org.apache.arrow.flight.Location.forGrpcInsecure; import static org.junit.jupiter.api.Assertions.fail; @@ -139,7 +140,7 @@ public void supportsNullSchemas() throws Exception public FlightInfo getFlightInfo(CallContext context, FlightDescriptor descriptor) { return new FlightInfo(null, descriptor, Collections.emptyList(), - 0, 0, false, IpcOption.DEFAULT, "foo".getBytes()); + 0, 0, false, IpcOption.DEFAULT, "foo".getBytes(UTF_8)); } }; @@ -149,7 +150,7 @@ public FlightInfo getFlightInfo(CallContext context, FlightInfo flightInfo = client.getInfo(FlightDescriptor.path("test")); Assertions.assertEquals(Optional.empty(), flightInfo.getSchemaOptional()); Assertions.assertEquals(new Schema(Collections.emptyList()), flightInfo.getSchema()); - Assertions.assertArrayEquals(flightInfo.getAppMetadata(), "foo".getBytes()); + Assertions.assertArrayEquals(flightInfo.getAppMetadata(), "foo".getBytes(UTF_8)); Exception e = Assertions.assertThrows( FlightRuntimeException.class, diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java index 1feb6afcf8f..430dc29a7d0 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java @@ -17,6 +17,7 @@ package org.apache.arrow.flight; +import static com.google.common.collect.ImmutableList.toImmutableList; import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST; import static org.apache.arrow.flight.Location.forGrpcInsecure; @@ -89,7 +90,7 @@ private static VectorSchemaRoot generateData(BufferAllocator allocator) { final Stream fields = fieldNames .stream() .map(fieldName -> new Field(fieldName, FieldType.nullable(new ArrowType.Int(32, true)), null)); - final Schema schema = new Schema(fields::iterator, null); + final Schema schema = new Schema(fields.collect(toImmutableList()), null); final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator); root.allocateNew(); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java index 0e19468d2b4..e209f62402c 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java @@ -38,15 +38,13 @@ public class TestServerMiddleware { - private static final RuntimeException EXPECTED_EXCEPTION = new RuntimeException("test"); - /** * Make sure errors in DoPut are intercepted. */ @Test public void doPutErrors() { test( - new ErrorProducer(EXPECTED_EXCEPTION), + new ErrorProducer(new RuntimeException("test")), (allocator, client) -> { final FlightDescriptor descriptor = FlightDescriptor.path("test"); try (final VectorSchemaRoot root = VectorSchemaRoot.create(new Schema(Collections.emptyList()), allocator)) { @@ -91,7 +89,7 @@ public void doPutCustomCode() { */ @Test public void doPutUncaught() { - test(new ServerErrorProducer(EXPECTED_EXCEPTION), + test(new ServerErrorProducer(new RuntimeException("test")), (allocator, client) -> { final FlightDescriptor descriptor = FlightDescriptor.path("test"); try (final VectorSchemaRoot root = VectorSchemaRoot.create(new Schema(Collections.emptyList()), allocator)) { @@ -106,13 +104,13 @@ public void doPutUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(EXPECTED_EXCEPTION.getMessage(), err.getMessage()); + Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); }); } @Test public void listFlightsUncaught() { - test(new ServerErrorProducer(EXPECTED_EXCEPTION), + test(new ServerErrorProducer(new RuntimeException("test")), (allocator, client) -> client.listFlights(new Criteria(new byte[0])).forEach((action) -> { }), (recorder) -> { final CallStatus status = recorder.statusFuture.get(); @@ -121,13 +119,13 @@ public void listFlightsUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(EXPECTED_EXCEPTION.getMessage(), err.getMessage()); + Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); }); } @Test public void doActionUncaught() { - test(new ServerErrorProducer(EXPECTED_EXCEPTION), + test(new ServerErrorProducer(new RuntimeException("test")), (allocator, client) -> client.doAction(new Action("test")).forEachRemaining(result -> { }), (recorder) -> { final CallStatus status = recorder.statusFuture.get(); @@ -136,13 +134,13 @@ public void doActionUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(EXPECTED_EXCEPTION.getMessage(), err.getMessage()); + Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); }); } @Test public void listActionsUncaught() { - test(new ServerErrorProducer(EXPECTED_EXCEPTION), + test(new ServerErrorProducer(new RuntimeException("test")), (allocator, client) -> client.listActions().forEach(result -> { }), (recorder) -> { final CallStatus status = recorder.statusFuture.get(); @@ -151,13 +149,13 @@ public void listActionsUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(EXPECTED_EXCEPTION.getMessage(), err.getMessage()); + Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); }); } @Test public void getFlightInfoUncaught() { - test(new ServerErrorProducer(EXPECTED_EXCEPTION), + test(new ServerErrorProducer(new RuntimeException("test")), (allocator, client) -> { FlightTestUtil.assertCode(FlightStatusCode.INTERNAL, () -> client.getInfo(FlightDescriptor.path("test"))); }, (recorder) -> { @@ -165,13 +163,13 @@ public void getFlightInfoUncaught() { Assertions.assertNotNull(status); Assertions.assertEquals(FlightStatusCode.INTERNAL, status.code()); Assertions.assertNotNull(status.cause()); - Assertions.assertEquals(EXPECTED_EXCEPTION.getMessage(), status.cause().getMessage()); + Assertions.assertEquals(new RuntimeException("test").getMessage(), status.cause().getMessage()); }); } @Test public void doGetUncaught() { - test(new ServerErrorProducer(EXPECTED_EXCEPTION), + test(new ServerErrorProducer(new RuntimeException("test")), (allocator, client) -> { try (final FlightStream stream = client.getStream(new Ticket(new byte[0]))) { while (stream.next()) { @@ -186,7 +184,7 @@ public void doGetUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(EXPECTED_EXCEPTION.getMessage(), err.getMessage()); + Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); }); } @@ -305,7 +303,7 @@ static class ServerMiddlewarePair { final FlightServerMiddleware.Key key; final FlightServerMiddleware.Factory factory; - ServerMiddlewarePair(Key key, Factory factory) { + ServerMiddlewarePair(FlightServerMiddleware.Key key, FlightServerMiddleware.Factory factory) { this.key = key; this.factory = factory; } @@ -339,7 +337,7 @@ static void test(FlightProducer producer, BiConsumer verify) { final ErrorRecorder.Factory factory = new ErrorRecorder.Factory(); final List> middleware = Collections - .singletonList(new ServerMiddlewarePair<>(Key.of("m"), factory)); + .singletonList(new ServerMiddlewarePair<>(FlightServerMiddleware.Key.of("m"), factory)); test(producer, middleware, (allocator, client) -> { body.accept(allocator, client); try { diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java index 0f6697a8e51..1f982d0d6cd 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java @@ -105,7 +105,7 @@ public void connectTlsDisableServerVerification() { }); } - void test(Consumer testFn) { + void test(Consumer testFn) { final FlightTestUtil.CertKeyPair certKey = FlightTestUtil.exampleTlsCerts().get(0); try ( BufferAllocator a = new RootAllocator(Long.MAX_VALUE); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java index 4b8a11870da..d34a3a2d3a5 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java @@ -251,6 +251,7 @@ public ClientCookieMiddleware onCallStarted(CallInfo info) { private void startServerAndClient() throws IOException { final FlightProducer flightProducer = new NoOpFlightProducer() { + @Override public void listFlights(CallContext context, Criteria criteria, StreamListener listener) { listener.onCompleted(); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java index 17c83c205fe..73d7465da29 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java @@ -157,7 +157,7 @@ public Result call() throws Exception { aSum += a.get(i); } } - r.bytes += rows * 32; + r.bytes += rows * 32L; r.rows += rows; r.aSum = aSum; r.batches++; @@ -173,7 +173,7 @@ public Result call() throws Exception { } - private final class Result { + private static final class Result { private long rows; private long aSum; private long bytes; From c3eb1d4366ab836c4c7a1719eaa3c81934595749 Mon Sep 17 00:00:00 2001 From: Vibhatha Lakmal Abeykoon Date: Tue, 9 Jan 2024 08:33:27 +0530 Subject: [PATCH 02/23] fixing warnings v2 --- .../apache/arrow/flight/FlightTestUtil.java | 3 -- .../arrow/flight/TestApplicationMetadata.java | 3 +- .../apache/arrow/flight/TestBackPressure.java | 6 ++-- .../apache/arrow/flight/TestCallOptions.java | 7 ++-- .../arrow/flight/TestDictionaryUtils.java | 8 ++--- .../apache/arrow/flight/TestDoExchange.java | 14 ++++---- .../arrow/flight/TestErrorMetadata.java | 4 ++- .../java/org/apache/arrow/flight/TestTls.java | 4 +-- .../flight/perf/PerformanceTestServer.java | 35 +++++++------------ .../apache/arrow/flight/perf/TestPerf.java | 12 +++---- 10 files changed, 45 insertions(+), 51 deletions(-) diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java index 11510dbd320..393fa086775 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java @@ -23,7 +23,6 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; -import java.util.Random; import org.apache.arrow.vector.test.util.ArrowTestDataUtil; import org.junit.jupiter.api.Assertions; @@ -34,8 +33,6 @@ */ public class FlightTestUtil { - private static final Random RANDOM = new Random(); - public static final String LOCALHOST = "localhost"; static Path getFlightTestDataRoot() { diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java index 07db301309e..77c039afd87 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java @@ -20,6 +20,7 @@ import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST; import static org.apache.arrow.flight.Location.forGrpcInsecure; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.concurrent.ExecutionException; @@ -45,7 +46,7 @@ public class TestApplicationMetadata { // The command used to trigger the test for ARROW-6136. - private static final byte[] COMMAND_ARROW_6136 = "ARROW-6136".getBytes(); + private static final byte[] COMMAND_ARROW_6136 = "ARROW-6136".getBytes(StandardCharsets.UTF_8); // The expected error message. private static final String MESSAGE_ARROW_6136 = "The stream should not be double-closed."; diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java index 7586d50c8e7..596debcf89d 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java @@ -22,6 +22,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; @@ -153,7 +154,7 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l loadData.run(); } else { final ExecutorService service = Executors.newSingleThreadExecutor(); - service.submit(loadData); + Future unused = service.submit(loadData); service.shutdown(); } } @@ -237,7 +238,8 @@ public WaitResult waitForListener(long timeout) { try { Thread.sleep(1); sleepTime.addAndGet(1L); - } catch (InterruptedException ignore) { + } catch (InterruptedException expected) { + // it is expected and no action needed } } return WaitResult.READY; diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java index 8b1a897467d..41df36c8633 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java @@ -21,6 +21,7 @@ import static org.apache.arrow.flight.Location.forGrpcInsecure; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; import java.util.Iterator; @@ -87,8 +88,8 @@ public void multipleProperties() { @Test public void binaryProperties() { final FlightCallHeaders headers = new FlightCallHeaders(); - headers.insert("key-bin", "value".getBytes()); - headers.insert("key3-bin", "ëfßæ".getBytes()); + headers.insert("key-bin", "value".getBytes(StandardCharsets.UTF_8)); + headers.insert("key3-bin", "ëfßæ".getBytes(StandardCharsets.UTF_8)); testHeaders(headers); } @@ -96,7 +97,7 @@ public void binaryProperties() { public void mixedProperties() { final FlightCallHeaders headers = new FlightCallHeaders(); headers.insert("key", "value"); - headers.insert("key3-bin", "ëfßæ".getBytes()); + headers.insert("key3-bin", "ëfßæ".getBytes(StandardCharsets.UTF_8)); testHeaders(headers); } diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java index 7aa8b9bd182..9e33136c107 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java @@ -17,6 +17,10 @@ package org.apache.arrow.flight; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + import java.util.TreeSet; import org.apache.arrow.memory.BufferAllocator; @@ -33,10 +37,6 @@ import com.google.common.collect.ImmutableList; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertSame; - /** * Test cases for {@link DictionaryUtils}. */ diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDoExchange.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDoExchange.java index f9db9bfd23a..b70353df8e9 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDoExchange.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDoExchange.java @@ -476,7 +476,7 @@ public void doExchange(CallContext context, FlightStream reader, ServerStreamLis } /** Emulate DoGet. */ - private void doGet(CallContext context, FlightStream reader, ServerStreamListener writer) { + private void doGet(CallContext unusedContext, FlightStream unusedReader, ServerStreamListener writer) { try (VectorSchemaRoot root = VectorSchemaRoot.create(SCHEMA, allocator)) { writer.start(root); root.allocateNew(); @@ -493,7 +493,7 @@ private void doGet(CallContext context, FlightStream reader, ServerStreamListene } /** Emulate DoPut. */ - private void doPut(CallContext context, FlightStream reader, ServerStreamListener writer) { + private void doPut(CallContext unusedContext, FlightStream reader, ServerStreamListener writer) { int counter = 0; while (reader.next()) { if (!reader.hasRoot()) { @@ -510,7 +510,7 @@ private void doPut(CallContext context, FlightStream reader, ServerStreamListene } /** Exchange metadata without ever exchanging data. */ - private void metadataOnly(CallContext context, FlightStream reader, ServerStreamListener writer) { + private void metadataOnly(CallContext unusedContext, FlightStream reader, ServerStreamListener writer) { final ArrowBuf buf = allocator.buffer(4); buf.writeInt(42); writer.putMetadata(buf); @@ -522,7 +522,7 @@ private void metadataOnly(CallContext context, FlightStream reader, ServerStream } /** Echo the client's response back to it. */ - private void echo(CallContext context, FlightStream reader, ServerStreamListener writer) { + private void echo(CallContext unusedContext, FlightStream reader, ServerStreamListener writer) { VectorSchemaRoot root = null; VectorLoader loader = null; while (reader.next()) { @@ -555,7 +555,7 @@ private void echo(CallContext context, FlightStream reader, ServerStreamListener } /** Accept a set of messages, then return some result. */ - private void transform(CallContext context, FlightStream reader, ServerStreamListener writer) { + private void transform(CallContext unusedContext, FlightStream reader, ServerStreamListener writer) { final Schema schema = reader.getSchema(); for (final Field field : schema.getFields()) { if (!(field.getType() instanceof ArrowType.Int)) { @@ -597,11 +597,11 @@ private void transform(CallContext context, FlightStream reader, ServerStreamLis } /** Immediately cancel the call. */ - private void cancel(CallContext context, FlightStream reader, ServerStreamListener writer) { + private void cancel(CallContext unusedContext, FlightStream unusedReader, ServerStreamListener writer) { writer.error(CallStatus.CANCELLED.withDescription("expected").toRuntimeException()); } - private void error(CallContext context, FlightStream reader, ServerStreamListener writer) { + private void error(CallContext unusedContext, FlightStream reader, ServerStreamListener writer) { VectorSchemaRoot root = null; VectorLoader loader = null; while (reader.next()) { diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java index 1987d98196e..4ec73014662 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java @@ -20,6 +20,8 @@ import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST; import static org.apache.arrow.flight.Location.forGrpcInsecure; +import java.nio.charset.StandardCharsets; + import org.apache.arrow.flight.perf.impl.PerfOuterClass; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -53,7 +55,7 @@ public void testGrpcMetadata() throws Exception { .start(); final FlightClient client = FlightClient.builder(allocator, s.getLocation()).build()) { final CallStatus flightStatus = FlightTestUtil.assertCode(FlightStatusCode.CANCELLED, () -> { - FlightStream stream = client.getStream(new Ticket("abs".getBytes())); + FlightStream stream = client.getStream(new Ticket("abs".getBytes(StandardCharsets.UTF_8))); stream.next(); }); PerfOuterClass.Perf newPerf = null; diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java index 1f982d0d6cd..75bc5f6e615 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java @@ -27,7 +27,6 @@ import java.util.Iterator; import java.util.function.Consumer; -import org.apache.arrow.flight.FlightClient.Builder; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.junit.jupiter.api.Assertions; @@ -113,7 +112,8 @@ void test(Consumer testFn) { FlightServer s = FlightServer.builder(a, forGrpcInsecure(LOCALHOST, 0), producer) .useTls(certKey.cert, certKey.key) .build().start()) { - final Builder builder = FlightClient.builder(a, Location.forGrpcTls(FlightTestUtil.LOCALHOST, s.getPort())); + final FlightClient.Builder builder = FlightClient.builder(a, Location.forGrpcTls(FlightTestUtil.LOCALHOST, + s.getPort())); testFn.accept(builder); } catch (InterruptedException | IOException e) { throw new RuntimeException(e); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java index 0ded2f7065f..b1e83ea61ed 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.apache.arrow.flight.BackpressureStrategy; import org.apache.arrow.flight.FlightDescriptor; @@ -48,10 +49,7 @@ public class PerformanceTestServer implements AutoCloseable { - private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PerformanceTestServer.class); - private final FlightServer flightServer; - private final Location location; private final BufferAllocator allocator; private final PerfProducer producer; private final boolean isNonBlocking; @@ -78,7 +76,6 @@ public WaitResult waitForListener(long timeout) { public PerformanceTestServer(BufferAllocator incomingAllocator, Location location, BackpressureStrategy bpStrategy, boolean isNonBlocking) { this.allocator = incomingAllocator.newChildAllocator("perf-server", 0, Long.MAX_VALUE); - this.location = location; this.producer = new PerfProducer(bpStrategy); this.flightServer = FlightServer.builder(this.allocator, location, producer).build(); this.isNonBlocking = isNonBlocking; @@ -110,16 +107,18 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener listener) { bpStrategy.register(listener); final Runnable loadData = () -> { - VectorSchemaRoot root = null; + Token token = null; try { - Token token = Token.parseFrom(ticket.getBytes()); - Perf perf = token.getDefinition(); - Schema schema = Schema.deserializeMessage(perf.getSchema().asReadOnlyByteBuffer()); - root = VectorSchemaRoot.create(schema, allocator); - BigIntVector a = (BigIntVector) root.getVector("a"); - BigIntVector b = (BigIntVector) root.getVector("b"); - BigIntVector c = (BigIntVector) root.getVector("c"); - BigIntVector d = (BigIntVector) root.getVector("d"); + token = Token.parseFrom(ticket.getBytes()); + } catch (InvalidProtocolBufferException e) { + throw new RuntimeException(e); + } + Perf perf = token.getDefinition(); + Schema schema = Schema.deserializeMessage(perf.getSchema().asReadOnlyByteBuffer()); + try ( + VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator); + BigIntVector a = (BigIntVector) root.getVector("a") + ) { listener.setUseZeroCopy(true); listener.start(root); root.allocateNew(); @@ -158,14 +157,6 @@ public void getStream(CallContext context, Ticket ticket, listener.putNext(); } listener.completed(); - } catch (InvalidProtocolBufferException e) { - throw new RuntimeException(e); - } finally { - try { - AutoCloseables.close(root); - } catch (Exception e) { - throw new RuntimeException(e); - } } }; @@ -173,7 +164,7 @@ public void getStream(CallContext context, Ticket ticket, loadData.run(); } else { final ExecutorService service = Executors.newSingleThreadExecutor(); - service.submit(loadData); + Future unused = service.submit(loadData); service.shutdown(); } } diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java index 73d7465da29..290e82de36c 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java @@ -110,14 +110,14 @@ public void throughput() throws Exception { double seconds = r.nanos * 1.0d / 1000 / 1000 / 1000; throughPuts[i] = (r.bytes * 1.0d / 1024 / 1024) / seconds; - System.out.println(String.format( - "Transferred %d records totaling %s bytes at %f MiB/s. %f record/s. %f batch/s.", + System.out.printf( + "Transferred %d records totaling %s bytes at %f MiB/s. %f record/s. %f batch/s.%n", r.rows, r.bytes, throughPuts[i], (r.rows * 1.0d) / seconds, (r.batches * 1.0d) / seconds - )); + ); } } pool.shutdown(); @@ -126,11 +126,11 @@ public void throughput() throws Exception { double average = Arrays.stream(throughPuts).sum() / numRuns; double sqrSum = Arrays.stream(throughPuts).map(val -> val - average).map(val -> val * val).sum(); double stddev = Math.sqrt(sqrSum / numRuns); - System.out.println(String.format("Average throughput: %f MiB/s, standard deviation: %f MiB/s", - average, stddev)); + System.out.printf("Average throughput: %f MiB/s, standard deviation: %f MiB/s%n", + average, stddev); } - private final class Consumer implements Callable { + private static final class Consumer implements Callable { private final FlightClient client; private final Ticket ticket; From 877f52d6e8ee7725f8668e990a8bb2d3675fa194 Mon Sep 17 00:00:00 2001 From: Vibhatha Lakmal Abeykoon Date: Tue, 9 Jan 2024 13:45:12 +0530 Subject: [PATCH 03/23] fixing warnings v3 --- .../arrow/flight/CancelFlightInfoResult.java | 2 +- .../arrow/flight/ErrorFlightMetadata.java | 2 +- .../arrow/flight/FlightCallHeaders.java | 11 +++++--- .../arrow/flight/FlightRuntimeException.java | 2 +- .../org/apache/arrow/flight/FlightServer.java | 28 +++++++++++-------- .../apache/arrow/flight/FlightService.java | 22 ++++++++------- .../arrow/flight/auth/AuthConstants.java | 4 +-- .../auth2/BearerTokenAuthenticator.java | 1 - .../arrow/flight/grpc/AddWritableBuffer.java | 2 +- .../flight/grpc/ClientInterceptorAdapter.java | 4 +-- .../arrow/flight/grpc/GetReadableBuffer.java | 2 +- .../arrow/flight/grpc/MetadataAdapter.java | 20 +++++++------ .../flight/grpc/ServerInterceptorAdapter.java | 2 +- .../apache/arrow/flight/grpc/StatusUtils.java | 3 +- 14 files changed, 58 insertions(+), 47 deletions(-) diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/CancelFlightInfoResult.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/CancelFlightInfoResult.java index eff5afdeeb7..165afdff553 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/CancelFlightInfoResult.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/CancelFlightInfoResult.java @@ -105,7 +105,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof CancelFlightInfoResult)) { return false; } CancelFlightInfoResult that = (CancelFlightInfoResult) o; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ErrorFlightMetadata.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ErrorFlightMetadata.java index 6669ce46550..6e19d2750cb 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ErrorFlightMetadata.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ErrorFlightMetadata.java @@ -61,7 +61,7 @@ public Iterable getAllByte(String key) { @Override public void insert(String key, String value) { - metadata.put(key, value.getBytes()); + metadata.put(key, value.getBytes(StandardCharsets.UTF_8)); } @Override diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java index dd26d190872..6b730fb841d 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java @@ -17,6 +17,8 @@ package org.apache.arrow.flight; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; @@ -46,7 +48,7 @@ public String get(String key) { } if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { - return new String((byte[]) Iterables.get(values, 0)); + return new String((byte[]) Iterables.get(values, 0), UTF_8); } return (String) Iterables.get(values, 0); @@ -63,13 +65,13 @@ public byte[] getByte(String key) { return (byte[]) Iterables.get(values, 0); } - return ((String) Iterables.get(values, 0)).getBytes(); + return ((String) Iterables.get(values, 0)).getBytes(UTF_8); } @Override public Iterable getAll(String key) { if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { - return this.keysAndValues.get(key).stream().map(o -> new String((byte[]) o)).collect(Collectors.toList()); + return this.keysAndValues.get(key).stream().map(o -> new String((byte[]) o, UTF_8)).collect(Collectors.toList()); } return (Collection) (Collection) this.keysAndValues.get(key); } @@ -79,7 +81,7 @@ public Iterable getAllByte(String key) { if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { return (Collection) (Collection) this.keysAndValues.get(key); } - return this.keysAndValues.get(key).stream().map(o -> ((String) o).getBytes()).collect(Collectors.toList()); + return this.keysAndValues.get(key).stream().map(o -> ((String) o).getBytes(UTF_8)).collect(Collectors.toList()); } @Override @@ -105,6 +107,7 @@ public boolean containsKey(String key) { return this.keysAndValues.containsKey(key); } + @Override public String toString() { return this.keysAndValues.toString(); } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java index 76d3349a2c3..a22b4614cbf 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java @@ -39,7 +39,7 @@ public CallStatus status() { } @Override - public String toString() { + public String getMessage() { String s = getClass().getName(); return String.format("%s: %s: %s", s, status.code(), status.description()); } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightServer.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightServer.java index 234c9bdcaac..d873f7d2828 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightServer.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightServer.java @@ -21,6 +21,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -134,6 +135,7 @@ public boolean awaitTermination(final long timeout, final TimeUnit unit) throws } /** Shutdown the server, waits for up to 6 seconds for successful shutdown before returning. */ + @Override public void close() throws InterruptedException { shutdown(); final boolean terminated = awaitTermination(3000, TimeUnit.MILLISECONDS); @@ -146,7 +148,7 @@ public void close() throws InterruptedException { server.shutdownNow(); int count = 0; - while (!server.isTerminated() & count < 30) { + while (!server.isTerminated() && count < 30) { count++; logger.debug("Waiting for termination"); Thread.sleep(100); @@ -216,22 +218,23 @@ public FlightServer build() { try { try { // Linux - builder.channelType( - (Class) Class - .forName("io.netty.channel.epoll.EpollServerDomainSocketChannel")); - final EventLoopGroup elg = (EventLoopGroup) Class.forName("io.netty.channel.epoll.EpollEventLoopGroup") - .newInstance(); + builder.channelType(Class + .forName("io.netty.channel.epoll.EpollServerDomainSocketChannel") + .asSubclass(ServerChannel.class)); + final EventLoopGroup elg = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup") + .asSubclass(EventLoopGroup.class).getConstructor().newInstance(); builder.bossEventLoopGroup(elg).workerEventLoopGroup(elg); } catch (ClassNotFoundException e) { // BSD builder.channelType( - (Class) Class - .forName("io.netty.channel.kqueue.KQueueServerDomainSocketChannel")); - final EventLoopGroup elg = (EventLoopGroup) Class.forName("io.netty.channel.kqueue.KQueueEventLoopGroup") - .newInstance(); + Class.forName("io.netty.channel.kqueue.KQueueServerDomainSocketChannel") + .asSubclass(ServerChannel.class)); + final EventLoopGroup elg = Class.forName("io.netty.channel.kqueue.KQueueEventLoopGroup") + .asSubclass(EventLoopGroup.class).getConstructor().newInstance(); builder.bossEventLoopGroup(elg).workerEventLoopGroup(elg); } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | + InvocationTargetException e) { throw new UnsupportedOperationException( "Could not find suitable Netty native transport implementation for domain socket address."); } @@ -342,7 +345,8 @@ private void closeInputStreamIfNotNull(InputStream stream) { if (stream != null) { try { stream.close(); - } catch (IOException ignored) { + } catch (IOException expected) { + // stream closes gracefully, doesn't expect an exception. } } } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java index 5231a7aaf76..5f4d803aacd 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.Map; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; import java.util.function.BooleanSupplier; import java.util.function.Consumer; @@ -142,7 +143,7 @@ public void listActions(Flight.Empty request, StreamObserver } private static class GetListener extends OutboundStreamListenerImpl implements ServerStreamListener { - private ServerCallStreamObserver responseObserver; + private final ServerCallStreamObserver serverCallResponseObserver; private final Consumer errorHandler; private Runnable onCancelHandler = null; private Runnable onReadyHandler = null; @@ -152,10 +153,10 @@ public GetListener(ServerCallStreamObserver responseObserver, Cons super(null, responseObserver); this.errorHandler = errorHandler; this.completed = false; - this.responseObserver = responseObserver; - this.responseObserver.setOnCancelHandler(this::onCancel); - this.responseObserver.setOnReadyHandler(this::onReady); - this.responseObserver.disableAutoInboundFlowControl(); + this.serverCallResponseObserver = responseObserver; + this.serverCallResponseObserver.setOnCancelHandler(this::onCancel); + this.serverCallResponseObserver.setOnReadyHandler(this::onReady); + this.serverCallResponseObserver.disableAutoInboundFlowControl(); } private void onCancel() { @@ -183,7 +184,7 @@ public void setOnReadyHandler(Runnable handler) { @Override public boolean isCancelled() { - return responseObserver.isCancelled(); + return serverCallResponseObserver.isCancelled(); } @Override @@ -228,7 +229,7 @@ public StreamObserver doPutCustom(final StreamObserver observer = fs.asObserver(); - executors.submit(() -> { + Future unused = executors.submit(() -> { try { producer.acceptPut(makeContext(responseObserver), fs, ackStream).run(); } catch (Throwable ex) { @@ -277,7 +278,8 @@ public void pollFlightInfo(Flight.FlightDescriptor request, StreamObserver, FlightServerMiddleware> middleware = ServerInterceptorAdapter.SERVER_MIDDLEWARE_KEY.get(); + final Map, FlightServerMiddleware> middleware = ServerInterceptorAdapter + .SERVER_MIDDLEWARE_KEY.get(); if (middleware == null || middleware.isEmpty()) { logger.error("Uncaught exception in Flight method body", t); return; @@ -377,7 +379,7 @@ public StreamObserver doExchangeCustom(StreamObserver observer = fs.asObserver(); try { - executors.submit(() -> { + Future unused = executors.submit(() -> { try { producer.doExchange(makeContext(responseObserver), fs, listener); } catch (Exception ex) { @@ -416,7 +418,7 @@ public boolean isCancelled() { } @Override - public T getMiddleware(Key key) { + public T getMiddleware(FlightServerMiddleware.Key key) { final Map, FlightServerMiddleware> middleware = ServerInterceptorAdapter.SERVER_MIDDLEWARE_KEY.get(); if (middleware == null) { return null; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth/AuthConstants.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth/AuthConstants.java index ac55872e5b1..e3ccdc626d7 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth/AuthConstants.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth/AuthConstants.java @@ -20,8 +20,8 @@ import org.apache.arrow.flight.FlightConstants; import io.grpc.Context; +import io.grpc.Metadata; import io.grpc.Metadata.BinaryMarshaller; -import io.grpc.Metadata.Key; import io.grpc.MethodDescriptor; /** @@ -32,7 +32,7 @@ public final class AuthConstants { public static final String HANDSHAKE_DESCRIPTOR_NAME = MethodDescriptor .generateFullMethodName(FlightConstants.SERVICE, "Handshake"); public static final String TOKEN_NAME = "Auth-Token-bin"; - public static final Key TOKEN_KEY = Key.of(TOKEN_NAME, new BinaryMarshaller() { + public static final Metadata.Key TOKEN_KEY = Metadata.Key.of(TOKEN_NAME, new BinaryMarshaller() { @Override public byte[] toBytes(byte[] value) { diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth2/BearerTokenAuthenticator.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth2/BearerTokenAuthenticator.java index 2006e0a2b12..5eb5863e792 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth2/BearerTokenAuthenticator.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth2/BearerTokenAuthenticator.java @@ -55,7 +55,6 @@ public AuthResult authenticate(CallHeaders incomingHeaders) { * Validate the bearer token. * @param bearerToken The bearer token to validate. * @return A successful AuthResult if validation succeeded. - * @throws Exception If the token validation fails. */ protected abstract AuthResult validateBearer(String bearerToken); diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java index 4a99ab22842..a4cacc71327 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java @@ -72,7 +72,7 @@ public class AddWritableBuffer { tmpBufChainOut = tmpBufChainOut2; } catch (Exception ex) { - new RuntimeException("Failed to initialize AddWritableBuffer, falling back to slow path", ex).printStackTrace(); + throw new RuntimeException("Failed to initialize AddWritableBuffer, falling back to slow path", ex); } bufConstruct = tmpConstruct; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java index ae11e526056..dccda26bbac 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java @@ -46,9 +46,9 @@ */ public class ClientInterceptorAdapter implements ClientInterceptor { - private final List factories; + private final List factories; - public ClientInterceptorAdapter(List factories) { + public ClientInterceptorAdapter(List factories) { this.factories = factories; } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java index 82cfd7f39c9..bd2e780a0ce 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java @@ -51,7 +51,7 @@ public class GetReadableBuffer { tmpField = f; tmpClazz = clazz; } catch (Exception e) { - new RuntimeException("Failed to initialize GetReadableBuffer, falling back to slow path", e).printStackTrace(); + throw new RuntimeException("Failed to initialize GetReadableBuffer, falling back to slow path", e); } READABLE_BUFFER = tmpField; BUFFER_INPUT_STREAM = tmpClazz; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/MetadataAdapter.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/MetadataAdapter.java index 4327f0ca85b..25e4fb0197f 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/MetadataAdapter.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/MetadataAdapter.java @@ -17,6 +17,7 @@ package org.apache.arrow.flight.grpc; +import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -42,26 +43,26 @@ public MetadataAdapter(Metadata metadata) { @Override public String get(String key) { - return this.metadata.get(Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); + return this.metadata.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); } @Override public byte[] getByte(String key) { if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { - return this.metadata.get(Key.of(key, Metadata.BINARY_BYTE_MARSHALLER)); + return this.metadata.get(Metadata.Key.of(key, Metadata.BINARY_BYTE_MARSHALLER)); } - return get(key).getBytes(); + return get(key).getBytes(StandardCharsets.UTF_8); } @Override public Iterable getAll(String key) { - return this.metadata.getAll(Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); + return this.metadata.getAll(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); } @Override public Iterable getAllByte(String key) { if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { - return this.metadata.getAll(Key.of(key, Metadata.BINARY_BYTE_MARSHALLER)); + return this.metadata.getAll(Metadata.Key.of(key, Metadata.BINARY_BYTE_MARSHALLER)); } return StreamSupport.stream(getAll(key).spliterator(), false) .map(String::getBytes).collect(Collectors.toList()); @@ -69,12 +70,12 @@ public Iterable getAllByte(String key) { @Override public void insert(String key, String value) { - this.metadata.put(Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value); + this.metadata.put(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), value); } @Override public void insert(String key, byte[] value) { - this.metadata.put(Key.of(key, Metadata.BINARY_BYTE_MARSHALLER), value); + this.metadata.put(Metadata.Key.of(key, Metadata.BINARY_BYTE_MARSHALLER), value); } @Override @@ -85,13 +86,14 @@ public Set keys() { @Override public boolean containsKey(String key) { if (key.endsWith("-bin")) { - final Key grpcKey = Key.of(key, Metadata.BINARY_BYTE_MARSHALLER); + final Metadata.Key grpcKey = Metadata.Key.of(key, Metadata.BINARY_BYTE_MARSHALLER); return this.metadata.containsKey(grpcKey); } - final Key grpcKey = Key.of(key, Metadata.ASCII_STRING_MARSHALLER); + final Metadata.Key grpcKey = Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER); return this.metadata.containsKey(grpcKey); } + @Override public String toString() { return this.metadata.toString(); } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ServerInterceptorAdapter.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ServerInterceptorAdapter.java index 9b038b9d492..70c667df560 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ServerInterceptorAdapter.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ServerInterceptorAdapter.java @@ -61,7 +61,7 @@ public static class KeyFactory { private final FlightServerMiddleware.Key key; private final FlightServerMiddleware.Factory factory; - public KeyFactory(Key key, Factory factory) { + public KeyFactory(FlightServerMiddleware.Key key, FlightServerMiddleware.Factory factory) { this.key = key; this.factory = factory; } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/StatusUtils.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/StatusUtils.java index 55e8418642d..7f0dcf2da3f 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/StatusUtils.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/StatusUtils.java @@ -17,6 +17,7 @@ package org.apache.arrow.flight.grpc; +import java.nio.charset.StandardCharsets; import java.util.Iterator; import java.util.Objects; import java.util.function.Function; @@ -171,7 +172,7 @@ private static ErrorFlightMetadata parseTrailers(Metadata trailers) { if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { metadata.insert(key, trailers.get(keyOfBinary(key))); } else { - metadata.insert(key, Objects.requireNonNull(trailers.get(keyOfAscii(key))).getBytes()); + metadata.insert(key, Objects.requireNonNull(trailers.get(keyOfAscii(key))).getBytes(StandardCharsets.UTF_8)); } } return metadata; From d1333ab5b0a3dd6248cac90b32a4267cd4ec0576 Mon Sep 17 00:00:00 2001 From: Vibhatha Lakmal Abeykoon Date: Tue, 9 Jan 2024 15:04:31 +0530 Subject: [PATCH 04/23] fixing warnings v4 --- .../java/org/apache/arrow/flight/FlightService.java | 3 ++- .../java/org/apache/arrow/flight/FlightStream.java | 11 ++++++----- .../arrow/flight/grpc/ClientInterceptorAdapter.java | 3 +-- .../org/apache/arrow/flight/TestFlightService.java | 10 ++++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java index 5f4d803aacd..7aedbea54f6 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java @@ -419,7 +419,8 @@ public boolean isCancelled() { @Override public T getMiddleware(FlightServerMiddleware.Key key) { - final Map, FlightServerMiddleware> middleware = ServerInterceptorAdapter.SERVER_MIDDLEWARE_KEY.get(); + final Map, FlightServerMiddleware> middleware = ServerInterceptorAdapter + .SERVER_MIDDLEWARE_KEY.get(); if (middleware == null) { return null; } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java index ad4ffcbebde..f6fd92794d9 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java @@ -27,6 +27,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.arrow.flight.ArrowMessage.HeaderType; import org.apache.arrow.flight.grpc.StatusUtils; @@ -76,7 +77,7 @@ public class FlightStream implements AutoCloseable { // we don't block forever trying to write to a server that has rejected a call. final CompletableFuture cancelled; - private volatile int pending = 1; + private final AtomicInteger pending = new AtomicInteger(); private volatile VectorSchemaRoot fulfilledRoot; private DictionaryProvider.MapDictionaryProvider dictionaries; private volatile VectorLoader loader; @@ -227,7 +228,7 @@ public boolean next() { return false; } - pending--; + pending.decrementAndGet(); requestOutstanding(); Object data = queue.take(); @@ -359,9 +360,9 @@ public ArrowBuf getLatestMetadata() { } private synchronized void requestOutstanding() { - if (pending < pendingTarget) { - requestor.request(pendingTarget - pending); - pending = pendingTarget; + if (pending.get() < pendingTarget) { + requestor.request(pendingTarget - pending.get()); + pending.set(pendingTarget); } } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java index dccda26bbac..db27aa481ec 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/ClientInterceptorAdapter.java @@ -23,7 +23,6 @@ import org.apache.arrow.flight.CallInfo; import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightClientMiddleware; -import org.apache.arrow.flight.FlightClientMiddleware.Factory; import org.apache.arrow.flight.FlightMethod; import org.apache.arrow.flight.FlightRuntimeException; import org.apache.arrow.flight.FlightStatusCode; @@ -59,7 +58,7 @@ public ClientCall interceptCall(MethodDescriptor client.getSchema(FlightDescriptor.path("test"))); - Assertions.assertEquals("No schema is present in FlightInfo", e.getMessage()); + String expectedMessage = "org.apache.arrow.flight.FlightRuntimeException: INVALID_ARGUMENT:" + + " No schema is present in FlightInfo"; + Assertions.assertEquals(expectedMessage, e.getMessage()); } } } From d75fd7a69384a2e149066939b304ad60911d6ac6 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Tue, 9 Jan 2024 16:41:13 +0530 Subject: [PATCH 05/23] fixing warnings v5 --- .../driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java index 43209d8913e..3f7edd03a7d 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java @@ -207,9 +207,12 @@ public void testShouldFailToPrepareStatementForBadStatement() { * we simply throw an `IllegalArgumentException` for queries not registered * in our `MockFlightSqlProducer`. */ + String expectedMessage = format("Error while executing SQL \"%s\": " + + "org.apache.arrow.flight.FlightRuntimeException: INVALID_ARGUMENT: Query not found", + badQuery); collector.checkThat( e.getMessage(), - is(format("Error while executing SQL \"%s\": Query not found", badQuery))); + is(expectedMessage)); } collector.checkThat(count, is(1)); } From f1b6cfcf982e0b6f06ada6c1d9067cd38686fa8a Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 10 Jan 2024 08:42:05 +0530 Subject: [PATCH 06/23] fixing warnings v6 --- .../org/apache/arrow/flight/ArrowMessage.java | 15 +++---------- .../org/apache/arrow/flight/FlightClient.java | 21 ++++++++++++------- .../apache/arrow/flight/FlightDescriptor.java | 2 +- .../apache/arrow/flight/FlightEndpoint.java | 7 ++++--- .../org/apache/arrow/flight/FlightInfo.java | 2 +- .../apache/arrow/flight/FlightService.java | 5 +++-- .../org/apache/arrow/flight/FlightStream.java | 13 ++++++++++-- .../org/apache/arrow/flight/Location.java | 4 ++-- .../java/org/apache/arrow/flight/Ticket.java | 2 +- 9 files changed, 40 insertions(+), 31 deletions(-) diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ArrowMessage.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ArrowMessage.java index b4ee835dee4..46cb282e9f3 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ArrowMessage.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/ArrowMessage.java @@ -35,8 +35,6 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.util.Preconditions; -import org.apache.arrow.vector.compression.NoCompressionCodec; -import org.apache.arrow.vector.ipc.message.ArrowBodyCompression; import org.apache.arrow.vector.ipc.message.ArrowDictionaryBatch; import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; import org.apache.arrow.vector.ipc.message.IpcOption; @@ -144,7 +142,6 @@ public static HeaderType getHeader(byte b) { private final MessageMetadataResult message; private final ArrowBuf appMetadata; private final List bufs; - private final ArrowBodyCompression bodyCompression; private final boolean tryZeroCopyWrite; public ArrowMessage(FlightDescriptor descriptor, Schema schema, IpcOption option) { @@ -155,7 +152,6 @@ public ArrowMessage(FlightDescriptor descriptor, Schema schema, IpcOption option bufs = ImmutableList.of(); this.descriptor = descriptor; this.appMetadata = null; - this.bodyCompression = NoCompressionCodec.DEFAULT_BODY_COMPRESSION; this.tryZeroCopyWrite = false; } @@ -172,7 +168,6 @@ public ArrowMessage(ArrowRecordBatch batch, ArrowBuf appMetadata, boolean tryZer this.bufs = ImmutableList.copyOf(batch.getBuffers()); this.descriptor = null; this.appMetadata = appMetadata; - this.bodyCompression = batch.getBodyCompression(); this.tryZeroCopyWrite = tryZeroCopy; } @@ -186,7 +181,6 @@ public ArrowMessage(ArrowDictionaryBatch batch, IpcOption option) { this.bufs = ImmutableList.copyOf(batch.getDictionary().getBuffers()); this.descriptor = null; this.appMetadata = null; - this.bodyCompression = batch.getDictionary().getBodyCompression(); this.tryZeroCopyWrite = false; } @@ -201,7 +195,6 @@ public ArrowMessage(ArrowBuf appMetadata) { this.bufs = ImmutableList.of(); this.descriptor = null; this.appMetadata = appMetadata; - this.bodyCompression = NoCompressionCodec.DEFAULT_BODY_COMPRESSION; this.tryZeroCopyWrite = false; } @@ -212,7 +205,6 @@ public ArrowMessage(FlightDescriptor descriptor) { this.bufs = ImmutableList.of(); this.descriptor = descriptor; this.appMetadata = null; - this.bodyCompression = NoCompressionCodec.DEFAULT_BODY_COMPRESSION; this.tryZeroCopyWrite = false; } @@ -227,7 +219,6 @@ private ArrowMessage(FlightDescriptor descriptor, MessageMetadataResult message, this.descriptor = descriptor; this.appMetadata = appMetadata; this.bufs = buf == null ? ImmutableList.of() : ImmutableList.of(buf); - this.bodyCompression = NoCompressionCodec.DEFAULT_BODY_COMPRESSION; this.tryZeroCopyWrite = false; } @@ -370,7 +361,7 @@ private static int readRawVarint32(InputStream is) throws IOException { * * @return InputStream */ - private InputStream asInputStream(BufferAllocator allocator) { + private InputStream asInputStream() { if (message == null) { // If we have no IPC message, it's a pure-metadata message final FlightData.Builder builder = FlightData.newBuilder(); @@ -422,7 +413,7 @@ private InputStream asInputStream(BufferAllocator allocator) { // Arrow buffer. This is susceptible to use-after-free, so we subclass CompositeByteBuf // below to tie the Arrow buffer refcnt to the Netty buffer refcnt allBufs.add(Unpooled.wrappedBuffer(b.nioBuffer()).retain()); - size += b.readableBytes(); + size += (int) b.readableBytes(); // [ARROW-4213] These buffers must be aligned to an 8-byte boundary in order to be readable from C++. if (b.readableBytes() % 8 != 0) { int paddingBytes = (int) (8 - (b.readableBytes() % 8)); @@ -543,7 +534,7 @@ public ArrowMessageHolderMarshaller(BufferAllocator allocator) { @Override public InputStream stream(ArrowMessage value) { - return value.asInputStream(allocator); + return value.asInputStream(); } @Override diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightClient.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightClient.java index 91e3b4d052f..fc491ebe0df 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightClient.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightClient.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -627,6 +628,7 @@ default boolean isCancelled() { /** * Shut down this client. */ + @Override public void close() throws InterruptedException { channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); allocator.close(); @@ -746,19 +748,24 @@ public FlightClient build() { try { // Linux builder.channelType( - (Class) Class.forName("io.netty.channel.epoll.EpollDomainSocketChannel")); - final EventLoopGroup elg = (EventLoopGroup) Class.forName("io.netty.channel.epoll.EpollEventLoopGroup") - .newInstance(); + Class.forName("io.netty.channel.epoll.EpollDomainSocketChannel") + .asSubclass(ServerChannel.class)); + final EventLoopGroup elg = + Class.forName("io.netty.channel.epoll.EpollEventLoopGroup").asSubclass(EventLoopGroup.class) + .getDeclaredConstructor().newInstance(); builder.eventLoopGroup(elg); } catch (ClassNotFoundException e) { // BSD builder.channelType( - (Class) Class.forName("io.netty.channel.kqueue.KQueueDomainSocketChannel")); - final EventLoopGroup elg = (EventLoopGroup) Class.forName("io.netty.channel.kqueue.KQueueEventLoopGroup") - .newInstance(); + Class.forName("io.netty.channel.kqueue.KQueueDomainSocketChannel") + .asSubclass(ServerChannel.class)); + final EventLoopGroup elg = Class.forName("io.netty.channel.kqueue.KQueueEventLoopGroup") + .asSubclass(EventLoopGroup.class) + .getDeclaredConstructor().newInstance(); builder.eventLoopGroup(elg); } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | + NoSuchMethodException | InvocationTargetException e) { throw new UnsupportedOperationException( "Could not find suitable Netty native transport implementation for domain socket address."); } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightDescriptor.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightDescriptor.java index 3eff011d9fe..1836f2edd94 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightDescriptor.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightDescriptor.java @@ -152,7 +152,7 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof FlightDescriptor)) { return false; } FlightDescriptor other = (FlightDescriptor) obj; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightEndpoint.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightEndpoint.java index 1967fe1d91c..41ead8e1fcd 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightEndpoint.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightEndpoint.java @@ -33,6 +33,7 @@ import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; +import com.google.protobuf.util.Timestamps; /** * POJO to convert to/from the underlying protobuf FlightEndpoint. @@ -85,11 +86,11 @@ private FlightEndpoint(Ticket ticket, Instant expirationTime, byte[] appMetadata } if (flt.hasExpirationTime()) { this.expirationTime = Instant.ofEpochSecond( - flt.getExpirationTime().getSeconds(), flt.getExpirationTime().getNanos()); + flt.getExpirationTime().getSeconds(), Timestamps.toNanos(flt.getExpirationTime())); } else { this.expirationTime = null; } - this.appMetadata = (flt.getAppMetadata().size() == 0 ? null : flt.getAppMetadata().toByteArray()); + this.appMetadata = (flt.getAppMetadata().isEmpty() ? null : flt.getAppMetadata().toByteArray()); this.ticket = new Ticket(flt.getTicket()); } @@ -163,7 +164,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof FlightEndpoint)) { return false; } FlightEndpoint that = (FlightEndpoint) o; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightInfo.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightInfo.java index b5279a304c8..39e5f5e3a3e 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightInfo.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightInfo.java @@ -249,7 +249,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof FlightInfo)) { return false; } FlightInfo that = (FlightInfo) o; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java index 7aedbea54f6..f55b47d2a94 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightService.java @@ -433,8 +433,9 @@ public T getMiddleware(FlightServerMiddleware } @Override - public Map, FlightServerMiddleware> getMiddleware() { - final Map, FlightServerMiddleware> middleware = ServerInterceptorAdapter.SERVER_MIDDLEWARE_KEY.get(); + public Map, FlightServerMiddleware> getMiddleware() { + final Map, FlightServerMiddleware> middleware = + ServerInterceptorAdapter.SERVER_MIDDLEWARE_KEY.get(); if (middleware == null) { return Collections.emptyMap(); } diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java index f6fd92794d9..7a5a941603a 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java @@ -57,9 +57,17 @@ */ public class FlightStream implements AutoCloseable { // Use AutoCloseable sentinel objects to simplify logic in #close - private final AutoCloseable DONE = () -> { + private final AutoCloseable DONE = new AutoCloseable() { + @Override + public void close() throws Exception { + + } }; - private final AutoCloseable DONE_EX = () -> { + private final AutoCloseable DONE_EX = new AutoCloseable() { + @Override + public void close() throws Exception { + + } }; private final BufferAllocator allocator; @@ -170,6 +178,7 @@ public FlightDescriptor getDescriptor() { * *

If the stream isn't complete and is cancellable, this method will cancel and drain the stream first. */ + @Override public void close() throws Exception { final List closeables = new ArrayList<>(); Throwable suppressor = null; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Location.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Location.java index 9dba773bf33..fe192aa0c3f 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Location.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Location.java @@ -71,7 +71,7 @@ public SocketAddress toSocketAddress() { case LocationSchemes.GRPC_DOMAIN_SOCKET: { try { // This dependency is not available on non-Unix platforms. - return (SocketAddress) Class.forName("io.netty.channel.unix.DomainSocketAddress") + return Class.forName("io.netty.channel.unix.DomainSocketAddress").asSubclass(SocketAddress.class) .getConstructor(String.class) .newInstance(uri.getPath()); } catch (InstantiationException | ClassNotFoundException | InvocationTargetException | @@ -144,7 +144,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof Location)) { return false; } Location location = (Location) o; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Ticket.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Ticket.java index a93cd087905..eb2f4af70d7 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Ticket.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/Ticket.java @@ -88,7 +88,7 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof Ticket)) { return false; } Ticket other = (Ticket) obj; From fc73df31bc340976093a583357c0cb1f6f71ae8c Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 10 Jan 2024 08:55:02 +0530 Subject: [PATCH 07/23] fixing warnings v7 --- .../java/org/apache/arrow/flight/TestFlightGrpcUtils.java | 2 +- .../arrow/flight/integration/tests/IntegrationTestClient.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightGrpcUtils.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightGrpcUtils.java index 9010f2d4a98..2569d2ac2b3 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightGrpcUtils.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightGrpcUtils.java @@ -176,7 +176,7 @@ public void testProxyChannelWithClosedChannel() throws IOException, InterruptedE /** * Private class used for testing purposes that overrides service behavior. */ - private class TestServiceAdapter extends TestServiceGrpc.TestServiceImplBase { + private static class TestServiceAdapter extends TestServiceGrpc.TestServiceImplBase { /** * gRPC service that receives an empty object & returns and empty protobuf object. diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java index 2ea9874f3de..64b5882c0f5 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java @@ -98,14 +98,14 @@ private void run(String[] args) throws Exception { Scenarios.getScenario(cmd.getOptionValue("scenario")).client(allocator, defaultLocation, client); } else { final String inputPath = cmd.getOptionValue("j"); - testStream(allocator, defaultLocation, client, inputPath); + testStream(allocator, client, inputPath); } } catch (InterruptedException e) { throw new RuntimeException(e); } } - private static void testStream(BufferAllocator allocator, Location server, FlightClient client, String inputPath) + private static void testStream(BufferAllocator allocator, FlightClient client, String inputPath) throws IOException { // 1. Read data from JSON and upload to server. FlightDescriptor descriptor = FlightDescriptor.path(inputPath); From 987a0e8ec2b18043644ea6c3c89a0f72ffba4ef1 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 10 Jan 2024 09:14:31 +0530 Subject: [PATCH 08/23] fixing warnings v8 --- .../apache/arrow/flight/sql/FlightSqlProducer.java | 2 +- .../arrow/flight/sql/example/FlightSqlExample.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java index e2d79129c1f..dbe39ab1d07 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java @@ -433,7 +433,7 @@ default void cancelFlightInfo(CancelFlightInfoRequest request, CallContext conte * @param info The FlightInfo of the query to cancel. * @param context Per-call context. * @param listener Whether cancellation succeeded. - * @deprecated Prefer {@link #cancelFlightInfo(FlightInfo, CallContext, StreamListener)}. + * @deprecated Prefer {@link #cancelFlightInfo(CancelFlightInfoRequest, CallContext, StreamListener)}. */ @Deprecated default void cancelQuery(FlightInfo info, CallContext context, StreamListener listener) { diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java index 11f38ded5fc..ea00900d665 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java @@ -69,6 +69,7 @@ import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -140,6 +141,7 @@ import org.apache.commons.pool2.impl.GenericObjectPool; import org.slf4j.Logger; +import com.google.common.base.Splitter; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.RemovalListener; @@ -422,11 +424,11 @@ private static int saveToVectors(final Map ve writer.startList(); if (createParamsValues != null) { - String[] split = createParamsValues.split(","); + List split = Splitter.on(',').splitToList(createParamsValues); - range(0, split.length) + range(0, split.size()) .forEach(i -> { - byte[] bytes = split[i].getBytes(UTF_8); + byte[] bytes = split.get(i).getBytes(UTF_8); Preconditions.checkState(bytes.length < 1024, "The amount of bytes is greater than what the ArrowBuf supports"); buf.setBytes(0, bytes); @@ -512,7 +514,7 @@ private static VectorSchemaRoot getTypeInfoRoot(CommandGetXdbcTypeInfo request, } }; } else { - predicate = (resultSet -> true); + predicate = resultSet -> true; } int rows = saveToVectors(mapper, typeInfo, true, predicate); @@ -685,7 +687,7 @@ public void getStreamPreparedStatement(final CommandPreparedStatementQuery comma public void closePreparedStatement(final ActionClosePreparedStatementRequest request, final CallContext context, final StreamListener listener) { // Running on another thread - executorService.submit(() -> { + Future unused = executorService.submit(() -> { try { preparedStatementLoadingCache.invalidate(request.getPreparedStatementHandle()); } catch (final Exception e) { @@ -774,7 +776,7 @@ public void listFlights(CallContext context, Criteria criteria, StreamListener listener) { // Running on another thread - executorService.submit(() -> { + Future unused = executorService.submit(() -> { try { final ByteString preparedStatementHandle = copyFrom(randomUUID().toString().getBytes(UTF_8)); // Ownership of the connection will be passed to the context. Do NOT close! From a4865bc37ad73f42cb596d1e834bb237e1845302 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 10 Jan 2024 11:07:47 +0530 Subject: [PATCH 09/23] fixing warnings v10 --- .../driver/jdbc/ArrowFlightJdbcDriver.java | 18 +++++++++------ .../driver/jdbc/ArrowFlightMetaImpl.java | 5 ----- .../ArrowFlightJdbcBaseIntVectorAccessor.java | 22 +++++++++---------- .../ArrowFlightJdbcBitVectorAccessor.java | 1 - .../ArrowFlightConnectionConfigImpl.java | 4 +++- .../driver/jdbc/utils/ConnectionWrapper.java | 8 +++---- .../arrow/driver/jdbc/utils/ConvertUtils.java | 7 +++--- .../arrow/driver/jdbc/utils/UrlParser.java | 4 +++- .../driver/jdbc/ArrowFlightJdbcArrayTest.java | 2 +- .../jdbc/ArrowFlightJdbcDriverTest.java | 4 +++- .../driver/jdbc/ConnectionMutualTlsTest.java | 4 ---- .../arrow/driver/jdbc/ResultSetTest.java | 12 ++++------ .../accessor/ArrowFlightJdbcAccessorTest.java | 8 +++---- ...FlightJdbcTimeStampVectorAccessorTest.java | 6 ++--- ...stractArrowFlightJdbcListAccessorTest.java | 6 ++--- ...rowFlightJdbcStructVectorAccessorTest.java | 4 ++-- .../ArrowFlightJdbcBitVectorAccessorTest.java | 2 +- .../jdbc/utils/MockFlightSqlProducer.java | 4 ++-- .../jdbc/utils/RootAllocatorTestRule.java | 19 ++++++++-------- .../jdbc/utils/ThrowableAssertionUtils.java | 2 +- 20 files changed, 68 insertions(+), 74 deletions(-) diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java index aa1b460fc13..9ec560085c7 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java @@ -27,6 +27,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.sql.SQLException; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -43,6 +44,9 @@ import org.apache.calcite.avatica.Meta; import org.apache.calcite.avatica.UnregisteredDriver; +import com.google.common.base.Ascii; +import com.google.common.base.Splitter; + /** * JDBC driver for querying data from an Apache Arrow Flight server. */ @@ -111,17 +115,17 @@ protected DriverVersion createDriverVersion() { final String parentName = properties.getProperty("org.apache.arrow.flight.name"); final String parentVersion = properties.getProperty("org.apache.arrow.flight.version"); - final String[] pVersion = parentVersion.split("\\."); + final List pVersion = Splitter.on('.').splitToList(parentVersion); - final int parentMajorVersion = Integer.parseInt(pVersion[0]); - final int parentMinorVersion = Integer.parseInt(pVersion[1]); + final int parentMajorVersion = Integer.parseInt(pVersion.get(0)); + final int parentMinorVersion = Integer.parseInt(pVersion.get(1)); final String childName = properties.getProperty("org.apache.arrow.flight.jdbc-driver.name"); final String childVersion = properties.getProperty("org.apache.arrow.flight.jdbc-driver.version"); - final String[] cVersion = childVersion.split("\\."); + final List cVersion = Splitter.on('.').splitToList(childVersion); - final int childMajorVersion = Integer.parseInt(cVersion[0]); - final int childMinorVersion = Integer.parseInt(cVersion[1]); + final int childMajorVersion = Integer.parseInt(cVersion.get(0)); + final int childMinorVersion = Integer.parseInt(cVersion.get(1)); version = new DriverVersion( childName, @@ -267,7 +271,7 @@ Optional> getUrlsArgs(String url) static Properties lowerCasePropertyKeys(final Properties properties) { final Properties resultProperty = new Properties(); - properties.forEach((k, v) -> resultProperty.put(k.toString().toLowerCase(), v)); + properties.forEach((k, v) -> resultProperty.put(Ascii.toLowerCase(k.toString()), v)); return resultProperty; } } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java index 38275091499..d25f03ac27b 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java @@ -255,11 +255,6 @@ private static final class StatementHandleKey { public final String connectionId; public final int id; - StatementHandleKey(String connectionId, int id) { - this.connectionId = connectionId; - this.id = id; - } - StatementHandleKey(StatementHandle statementHandle) { this.connectionId = statementHandle.connectionId; this.id = statementHandle.id; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java index aea9b75fa6c..8d2fe1cc703 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java @@ -46,59 +46,57 @@ public class ArrowFlightJdbcBaseIntVectorAccessor extends ArrowFlightJdbcAccesso private final MinorType type; private final boolean isUnsigned; - private final int bytesToAllocate; private final Getter getter; private final NumericHolder holder; public ArrowFlightJdbcBaseIntVectorAccessor(UInt1Vector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, true, UInt1Vector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, true, setCursorWasNull); } public ArrowFlightJdbcBaseIntVectorAccessor(UInt2Vector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, true, UInt2Vector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, true, setCursorWasNull); } public ArrowFlightJdbcBaseIntVectorAccessor(UInt4Vector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, true, UInt4Vector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, true, setCursorWasNull); } public ArrowFlightJdbcBaseIntVectorAccessor(UInt8Vector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, true, UInt8Vector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, true, setCursorWasNull); } public ArrowFlightJdbcBaseIntVectorAccessor(TinyIntVector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, false, TinyIntVector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, false, setCursorWasNull); } public ArrowFlightJdbcBaseIntVectorAccessor(SmallIntVector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, false, SmallIntVector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, false, setCursorWasNull); } public ArrowFlightJdbcBaseIntVectorAccessor(IntVector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, false, IntVector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, false, setCursorWasNull); } public ArrowFlightJdbcBaseIntVectorAccessor(BigIntVector vector, IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { - this(vector, currentRowSupplier, false, BigIntVector.TYPE_WIDTH, setCursorWasNull); + this(vector, currentRowSupplier, false, setCursorWasNull); } private ArrowFlightJdbcBaseIntVectorAccessor(BaseIntVector vector, IntSupplier currentRowSupplier, - boolean isUnsigned, int bytesToAllocate, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + boolean isUnsigned, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.type = vector.getMinorType(); this.holder = new NumericHolder(); this.getter = createGetter(vector); this.isUnsigned = isUnsigned; - this.bytesToAllocate = bytesToAllocate; } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java index f55fd12f9a5..67d98c2e698 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java @@ -32,7 +32,6 @@ public class ArrowFlightJdbcBitVectorAccessor extends ArrowFlightJdbcAccessor { private final BitVector vector; private final NullableBitHolder holder; - private static final int BYTES_T0_ALLOCATE = 1; /** * Constructor for the BitVectorAccessor. diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java index 6237a8b58d6..277e42cb975 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java @@ -33,6 +33,8 @@ import org.apache.calcite.avatica.ConnectionConfigImpl; import org.apache.calcite.avatica.ConnectionProperty; +import com.google.common.base.Ascii; + /** * A {@link ConnectionConfig} for the {@link ArrowFlightConnection}. */ @@ -234,7 +236,7 @@ public Object get(final Properties properties) { Preconditions.checkNotNull(properties, "Properties cannot be null."); Object value = properties.get(camelName); if (value == null) { - value = properties.get(camelName.toLowerCase()); + value = properties.get(Ascii.toLowerCase(camelName)); } if (required) { if (value == null) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java index 5ee43ce012e..c28071490ca 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java @@ -248,13 +248,13 @@ public PreparedStatement prepareStatement(final String sqlQuery, final int autoG } @Override - public PreparedStatement prepareStatement(final String sqlQuery, final int... columnIndices) + public PreparedStatement prepareStatement(final String sqlQuery, final int[] columnIndices) throws SQLException { return realConnection.prepareStatement(sqlQuery, columnIndices); } @Override - public PreparedStatement prepareStatement(final String sqlQuery, final String... columnNames) + public PreparedStatement prepareStatement(final String sqlQuery, final String[] columnNames) throws SQLException { return realConnection.prepareStatement(sqlQuery, columnNames); } @@ -306,12 +306,12 @@ public Properties getClientInfo() throws SQLException { } @Override - public Array createArrayOf(final String typeName, final Object... elements) throws SQLException { + public Array createArrayOf(final String typeName, final Object[] elements) throws SQLException { return realConnection.createArrayOf(typeName, elements); } @Override - public Struct createStruct(final String typeName, final Object... attributes) + public Struct createStruct(final String typeName, final Object[] attributes) throws SQLException { return realConnection.createStruct(typeName, attributes); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java index b21b03340e9..843fe0cb89d 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java @@ -49,7 +49,6 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.ColumnMetaData; import org.apache.calcite.avatica.proto.Common; -import org.apache.calcite.avatica.proto.Common.ColumnMetaData.Builder; /** * Convert objects between Arrow and Avatica. @@ -71,7 +70,7 @@ public static List convertArrowFieldsToColumnMetaDataList(final final Field field = fields.get(index); final ArrowType fieldType = field.getType(); - final Builder builder = Common.ColumnMetaData.newBuilder() + final Common.ColumnMetaData.Builder builder = Common.ColumnMetaData.newBuilder() .setOrdinal(index) .setColumnName(field.getName()) .setLabel(field.getName()); @@ -90,10 +89,10 @@ public static List convertArrowFieldsToColumnMetaDataList(final /** * Set on Column MetaData Builder. * - * @param builder {@link Builder} + * @param builder {@link Common.ColumnMetaData.Builder} * @param metadataMap {@link Map} */ - public static void setOnColumnMetaDataBuilder(final Builder builder, + public static void setOnColumnMetaDataBuilder(final Common.ColumnMetaData.Builder builder, final Map metadataMap) { final FlightSqlColumnMetadata columnMetadata = new FlightSqlColumnMetadata(metadataMap); final String catalogName = columnMetadata.getCatalogName(); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java index e52251f5391..ee5a63b8a61 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.Map; +import com.google.common.base.Splitter; + /** * URL Parser for extracting key values from a connection string. */ @@ -40,7 +42,7 @@ private UrlParser() { public static Map parse(String url, String separator) { Map resultMap = new HashMap<>(); if (url != null) { - String[] keyValues = url.split(separator); + Iterable keyValues = Splitter.onPattern(separator).split(url); for (String keyValue : keyValues) { try { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java index 90c926612f1..76f01514c95 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java @@ -140,7 +140,7 @@ public void testShouldGetResultSetReturnValidResultSetWithOffsets() throws SQLEx Assert.assertEquals((Object) resultSet.getInt(1), dataVector.getObject(count + 3)); count++; } - Assert.assertEquals(count, 5); + Assert.assertEquals(5, count); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java index 784fd5b292b..e1f64c9dd87 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java @@ -181,6 +181,8 @@ public void testConnectWithInsensitiveCasePropertyKeys2() throws Exception { /** * Tests whether an exception is thrown upon attempting to connect to a * malformed URI. + * + * @throws SQLException If an error occurs. */ @Test(expected = SQLException.class) public void testShouldThrowExceptionWhenAttemptingToConnectToMalformedUrl() throws SQLException { @@ -194,7 +196,7 @@ public void testShouldThrowExceptionWhenAttemptingToConnectToMalformedUrl() thro * Tests whether an exception is thrown upon attempting to connect to a * malformed URI. * - * @throws Exception If an error occurs. + * @throws SQLException If an error occurs. */ @Test(expected = SQLException.class) public void testShouldThrowExceptionWhenAttemptingToConnectToUrlNoPrefix() throws SQLException { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java index cc44cc57be9..03f15d77ade 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java @@ -50,8 +50,6 @@ public class ConnectionMutualTlsTest { @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final String tlsRootCertsPath; - - private static final String serverMTlsCACertPath; private static final String clientMTlsCertPath; private static final String badClientMTlsCertPath; private static final String clientMTlsKeyPath; @@ -68,8 +66,6 @@ public class ConnectionMutualTlsTest { final File serverMTlsCACert = FlightSqlTestCertificates.exampleCACert(); - serverMTlsCACertPath = serverMTlsCACert.getPath(); - final FlightSqlTestCertificates.CertKeyPair clientMTlsCertKey = FlightSqlTestCertificates.exampleTlsCerts().get(1); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java index 231371a923a..0e3e015a046 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java @@ -94,10 +94,6 @@ private static void resultSetNextUntilDone(ResultSet resultSet) throws SQLExcept } } - private static void setMaxRowsLimit(int maxRowsLimit, Statement statement) throws SQLException { - statement.setLargeMaxRows(maxRowsLimit); - } - /** * Tests whether the {@link ArrowFlightJdbcDriver} can run a query successfully. * @@ -411,9 +407,9 @@ public void testPartitionedFlightServer() throws Exception { // Construct the data-only nodes first. FlightProducer firstProducer = new PartitionedFlightSqlProducer.DataOnlyFlightSqlProducer( - new Ticket("first".getBytes()), firstPartition); + new Ticket("first".getBytes(StandardCharsets.UTF_8)), firstPartition); FlightProducer secondProducer = new PartitionedFlightSqlProducer.DataOnlyFlightSqlProducer( - new Ticket("second".getBytes()), secondPartition); + new Ticket("second".getBytes(StandardCharsets.UTF_8)), secondPartition); final FlightServer.Builder firstBuilder = FlightServer.builder( allocator, forGrpcInsecure("localhost", 0), firstProducer); @@ -427,10 +423,10 @@ public void testPartitionedFlightServer() throws Exception { firstServer.start(); secondServer.start(); final FlightEndpoint firstEndpoint = - new FlightEndpoint(new Ticket("first".getBytes()), firstServer.getLocation()); + new FlightEndpoint(new Ticket("first".getBytes(StandardCharsets.UTF_8)), firstServer.getLocation()); final FlightEndpoint secondEndpoint = - new FlightEndpoint(new Ticket("second".getBytes()), secondServer.getLocation()); + new FlightEndpoint(new Ticket("second".getBytes(StandardCharsets.UTF_8)), secondServer.getLocation()); // Finally start the root node. try (final PartitionedFlightSqlProducer rootProducer = new PartitionedFlightSqlProducer( diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java index 099b0122179..a9b5c46e01e 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java @@ -123,7 +123,7 @@ public void testShouldGetObjectWithBooleanClassReturnGetBoolean() throws SQLExce when(accessor.getObject(Boolean.class)).thenCallRealMethod(); - Assert.assertEquals(accessor.getObject(Boolean.class), true); + Assert.assertEquals(true, accessor.getObject(Boolean.class)); verify(accessor).getBoolean(); } @@ -134,7 +134,7 @@ public void testShouldGetObjectWithBigDecimalClassReturnGetBigDecimal() throws S when(accessor.getObject(BigDecimal.class)).thenCallRealMethod(); - Assert.assertEquals(accessor.getObject(BigDecimal.class), expected); + Assert.assertEquals(expected, accessor.getObject(BigDecimal.class)); verify(accessor).getBigDecimal(); } @@ -145,7 +145,7 @@ public void testShouldGetObjectWithStringClassReturnGetString() throws SQLExcept when(accessor.getObject(String.class)).thenCallRealMethod(); - Assert.assertEquals(accessor.getObject(String.class), expected); + Assert.assertEquals(expected, accessor.getObject(String.class)); verify(accessor).getString(); } @@ -167,7 +167,7 @@ public void testShouldGetObjectWithObjectClassReturnGetObject() throws SQLExcept when(accessor.getObject(Object.class)).thenCallRealMethod(); - Assert.assertEquals(accessor.getObject(Object.class), expected); + Assert.assertEquals(expected, accessor.getObject(Object.class)); verify(accessor).getObject(); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java index 38d842724b9..e2c17b2f085 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java @@ -179,7 +179,7 @@ public void testShouldGetTimestampReturnValidTimestampWithCalendar() throws Exce final Timestamp resultWithoutCalendar = accessor.getTimestamp(null); final Timestamp result = accessor.getTimestamp(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()) - + long offset = (long) timeZone.getOffset(resultWithoutCalendar.getTime()) - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); @@ -212,7 +212,7 @@ public void testShouldGetDateReturnValidDateWithCalendar() throws Exception { final Date resultWithoutCalendar = accessor.getDate(null); final Date result = accessor.getDate(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()) - + long offset = (long) timeZone.getOffset(resultWithoutCalendar.getTime()) - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); @@ -245,7 +245,7 @@ public void testShouldGetTimeReturnValidTimeWithCalendar() throws Exception { final Time resultWithoutCalendar = accessor.getTime(null); final Time result = accessor.getTime(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()) - + long offset = (long) timeZone.getOffset(resultWithoutCalendar.getTime()) - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java index b2eb8f1dbee..e958fb60ba4 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java @@ -114,7 +114,7 @@ public void testShouldGetObjectReturnValidList() throws Exception { accessorIterator.assertAccessorGetter(vector, AbstractArrowFlightJdbcListVectorAccessor::getObject, (accessor, currentRow) -> equalTo( - Arrays.asList(0, (currentRow), (currentRow) * 2, (currentRow) * 3, (currentRow) * 4))); + Arrays.asList(0, currentRow, currentRow * 2, currentRow * 3, currentRow * 4))); } @Test @@ -137,7 +137,7 @@ public void testShouldGetArrayReturnValidArray() throws Exception { Object[] arrayObject = (Object[]) array.getArray(); collector.checkThat(arrayObject, equalTo( - new Object[] {0, currentRow, (currentRow) * 2, (currentRow) * 3, (currentRow) * 4})); + new Object[] {0, currentRow, currentRow * 2, currentRow * 3, currentRow * 4})); }); } @@ -161,7 +161,7 @@ public void testShouldGetArrayReturnValidArrayPassingOffsets() throws Exception Object[] arrayObject = (Object[]) array.getArray(1, 3); collector.checkThat(arrayObject, equalTo( - new Object[] {currentRow, (currentRow) * 2, (currentRow) * 3})); + new Object[] {currentRow, currentRow * 2, currentRow * 3})); }); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java index b3c85fc0ab1..735fe9f40ba 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java @@ -202,8 +202,8 @@ public void testShouldGetObjectWorkWithNestedComplexData() throws SQLException { new ArrowFlightJdbcStructVectorAccessor(rootVector, () -> 0, (boolean wasNull) -> { }); - Assert.assertEquals(accessor.getObject(), expected); - Assert.assertEquals(accessor.getString(), expected.toString()); + Assert.assertEquals(expected, accessor.getObject()); + Assert.assertEquals(expected.toString(), accessor.getString()); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java index 809d6e8d353..00537bfa028 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java @@ -68,7 +68,7 @@ private void iterate(final CheckedFunction is(arrayToAssert[currentRow] ? result : resultIfFalse)) + (accessor, currentRow) -> is(arrayToAssert[currentRow] ? result : resultIfFalse) ); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java index c165bfb7ce3..52a397edab1 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java @@ -159,7 +159,7 @@ public void addSelectQuery(final String sqlCommand, final Schema schema, * @param updatedRows the number of rows affected. */ public void addUpdateQuery(final String sqlCommand, final long updatedRows) { - addUpdateQuery(sqlCommand, ((flightStream, putResultStreamListener) -> { + addUpdateQuery(sqlCommand, (flightStream, putResultStreamListener) -> { final DoPutUpdateResult result = DoPutUpdateResult.newBuilder().setRecordCount(updatedRows).build(); try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); @@ -171,7 +171,7 @@ public void addUpdateQuery(final String sqlCommand, final long updatedRows) { } finally { putResultStreamListener.onCompleted(); } - })); + }); } /** diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java index a200fc8d39c..fd8fb57fcaf 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java @@ -18,6 +18,7 @@ package org.apache.arrow.driver.jdbc.utils; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; @@ -456,9 +457,9 @@ public VarBinaryVector createVarBinaryVector() { public VarBinaryVector createVarBinaryVector(final String fieldName) { VarBinaryVector valueVector = new VarBinaryVector(fieldName, this.getRootAllocator()); valueVector.allocateNew(3); - valueVector.setSafe(0, (fieldName + "__BINARY_DATA_0001").getBytes()); - valueVector.setSafe(1, (fieldName + "__BINARY_DATA_0002").getBytes()); - valueVector.setSafe(2, (fieldName + "__BINARY_DATA_0003").getBytes()); + valueVector.setSafe(0, (fieldName + "__BINARY_DATA_0001").getBytes(StandardCharsets.UTF_8)); + valueVector.setSafe(1, (fieldName + "__BINARY_DATA_0002").getBytes(StandardCharsets.UTF_8)); + valueVector.setSafe(2, (fieldName + "__BINARY_DATA_0003").getBytes(StandardCharsets.UTF_8)); valueVector.setValueCount(3); return valueVector; @@ -472,9 +473,9 @@ public VarBinaryVector createVarBinaryVector(final String fieldName) { public LargeVarBinaryVector createLargeVarBinaryVector() { LargeVarBinaryVector valueVector = new LargeVarBinaryVector("", this.getRootAllocator()); valueVector.allocateNew(3); - valueVector.setSafe(0, "BINARY_DATA_0001".getBytes()); - valueVector.setSafe(1, "BINARY_DATA_0002".getBytes()); - valueVector.setSafe(2, "BINARY_DATA_0003".getBytes()); + valueVector.setSafe(0, "BINARY_DATA_0001".getBytes(StandardCharsets.UTF_8)); + valueVector.setSafe(1, "BINARY_DATA_0002".getBytes(StandardCharsets.UTF_8)); + valueVector.setSafe(2, "BINARY_DATA_0003".getBytes(StandardCharsets.UTF_8)); valueVector.setValueCount(3); return valueVector; @@ -488,9 +489,9 @@ public LargeVarBinaryVector createLargeVarBinaryVector() { public FixedSizeBinaryVector createFixedSizeBinaryVector() { FixedSizeBinaryVector valueVector = new FixedSizeBinaryVector("", this.getRootAllocator(), 16); valueVector.allocateNew(3); - valueVector.setSafe(0, "BINARY_DATA_0001".getBytes()); - valueVector.setSafe(1, "BINARY_DATA_0002".getBytes()); - valueVector.setSafe(2, "BINARY_DATA_0003".getBytes()); + valueVector.setSafe(0, "BINARY_DATA_0001".getBytes(StandardCharsets.UTF_8)); + valueVector.setSafe(1, "BINARY_DATA_0002".getBytes(StandardCharsets.UTF_8)); + valueVector.setSafe(2, "BINARY_DATA_0003".getBytes(StandardCharsets.UTF_8)); valueVector.setValueCount(3); return valueVector; diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java index f1bd44539ac..48334dc0f92 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java @@ -25,7 +25,7 @@ public class ThrowableAssertionUtils { private ThrowableAssertionUtils() { } - public static void simpleAssertThrowableClass( + public static void simpleAssertThrowableClass( final Class expectedThrowable, final ThrowingRunnable runnable) { try { runnable.run(); From c14420c8a20897f37c54028205b9e1de7ee0f943 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 10 Jan 2024 13:10:34 +0530 Subject: [PATCH 10/23] fixing warnings v11: all algorithms module --- .../algorithm/search/ParallelSearcher.java | 5 +- .../FixedWidthOutOfPlaceVectorSorter.java | 6 +- .../VariableWidthOutOfPlaceVectorSorter.java | 11 ++-- .../deduplicate/TestDeduplicationUtils.java | 6 +- .../TestVectorRunDeduplicator.java | 8 ++- .../TestHashTableBasedDictionaryBuilder.java | 59 ++++++++++--------- .../TestHashTableDictionaryEncoder.java | 27 +++++---- .../TestLinearDictionaryEncoder.java | 26 ++++---- .../TestSearchDictionaryEncoder.java | 26 ++++---- .../TestSearchTreeBasedDictionaryBuilder.java | 59 ++++++++++--------- .../algorithm/misc/TestPartialSumUtils.java | 2 +- .../arrow/algorithm/rank/TestVectorRank.java | 22 +++---- .../search/TestParallelSearcher.java | 5 +- .../search/TestVectorRangeSearcher.java | 2 +- .../algorithm/search/TestVectorSearcher.java | 6 +- .../sort/TestCompositeVectorComparator.java | 8 ++- .../sort/TestDefaultVectorComparator.java | 8 ++- .../algorithm/sort/TestFixedWidthSorting.java | 12 ++-- .../arrow/algorithm/sort/TestSortingUtil.java | 3 +- .../sort/TestStableVectorComparator.java | 56 ++++++++++-------- ...stVariableWidthOutOfPlaceVectorSorter.java | 35 ++++++----- .../sort/TestVariableWidthSorting.java | 11 ++-- 22 files changed, 217 insertions(+), 186 deletions(-) diff --git a/java/algorithm/src/main/java/org/apache/arrow/algorithm/search/ParallelSearcher.java b/java/algorithm/src/main/java/org/apache/arrow/algorithm/search/ParallelSearcher.java index e62ebdecb1b..6226921b22e 100644 --- a/java/algorithm/src/main/java/org/apache/arrow/algorithm/search/ParallelSearcher.java +++ b/java/algorithm/src/main/java/org/apache/arrow/algorithm/search/ParallelSearcher.java @@ -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; @@ -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; @@ -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; diff --git a/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/FixedWidthOutOfPlaceVectorSorter.java b/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/FixedWidthOutOfPlaceVectorSorter.java index c3b68facfda..05a4585792d 100644 --- a/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/FixedWidthOutOfPlaceVectorSorter.java +++ b/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/FixedWidthOutOfPlaceVectorSorter.java @@ -54,7 +54,7 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator 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()); @@ -73,8 +73,8 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator 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); } } diff --git a/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/VariableWidthOutOfPlaceVectorSorter.java b/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/VariableWidthOutOfPlaceVectorSorter.java index c60e273e9e8..863b07c348e 100644 --- a/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/VariableWidthOutOfPlaceVectorSorter.java +++ b/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/VariableWidthOutOfPlaceVectorSorter.java @@ -51,12 +51,12 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator 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()); @@ -77,15 +77,16 @@ public void sortOutOfPlace(V srcVector, V dstVector, VectorValueComparator 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); } } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestDeduplicationUtils.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestDeduplicationUtils.java index def83fba7b7..ac083b84f16 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestDeduplicationUtils.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestDeduplicationUtils.java @@ -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; @@ -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)); } } @@ -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( diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestVectorRunDeduplicator.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestVectorRunDeduplicator.java index 4bfa6e25551..788213b1628 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestVectorRunDeduplicator.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/deduplicate/TestVectorRunDeduplicator.java @@ -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; @@ -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); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableBasedDictionaryBuilder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableBasedDictionaryBuilder.java index 0a3314535f2..45c47626b72 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableBasedDictionaryBuilder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableBasedDictionaryBuilder.java @@ -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; @@ -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 dictionaryBuilder = new HashTableBasedDictionaryBuilder<>(dictionary, true); @@ -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)); } } @@ -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 dictionaryBuilder = new HashTableBasedDictionaryBuilder<>(dictionary, false); @@ -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)); } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java index dd22ac96fac..f33cfc21fab 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java @@ -17,12 +17,12 @@ package org.apache.arrow.algorithm.dictionary; +import static java.nio.charset.StandardCharsets.UTF_8; import static junit.framework.TestCase.assertTrue; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; @@ -49,9 +49,9 @@ public class TestHashTableDictionaryEncoder { private BufferAllocator allocator; - byte[] zero = "000".getBytes(StandardCharsets.UTF_8); - byte[] one = "111".getBytes(StandardCharsets.UTF_8); - byte[] two = "222".getBytes(StandardCharsets.UTF_8); + byte[] zero = "000".getBytes(UTF_8); + byte[] one = "111".getBytes(UTF_8); + byte[] two = "222".getBytes(UTF_8); byte[][] data = new byte[][]{zero, one, two}; @@ -76,7 +76,7 @@ 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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -84,7 +84,7 @@ public void testEncodeAndDecode() { 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(UTF_8)); } rawVector.setValueCount(VECTOR_LENGTH); @@ -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(UTF_8)); } // perform decoding @@ -108,7 +108,7 @@ 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(UTF_8), decodedVector.get(i)); } } } @@ -126,7 +126,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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -137,7 +137,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(UTF_8)); } } rawVector.setValueCount(VECTOR_LENGTH); @@ -155,7 +155,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(UTF_8)); } } @@ -168,7 +168,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(UTF_8), + decodedVector.get(i)); } } } @@ -185,7 +186,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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java index 104d1b35b06..77c939f330c 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java @@ -17,12 +17,12 @@ package org.apache.arrow.algorithm.dictionary; +import static java.nio.charset.StandardCharsets.UTF_8; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; @@ -50,9 +50,9 @@ public class TestLinearDictionaryEncoder { private BufferAllocator allocator; - byte[] zero = "000".getBytes(StandardCharsets.UTF_8); - byte[] one = "111".getBytes(StandardCharsets.UTF_8); - byte[] two = "222".getBytes(StandardCharsets.UTF_8); + byte[] zero = "000".getBytes(UTF_8); + byte[] one = "111".getBytes(UTF_8); + byte[] two = "222".getBytes(UTF_8); byte[][] data = new byte[][]{zero, one, two}; @@ -77,7 +77,7 @@ 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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -85,7 +85,7 @@ public void testEncodeAndDecode() { 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(UTF_8)); } rawVector.setValueCount(VECTOR_LENGTH); @@ -99,7 +99,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(UTF_8)); } // perform decoding @@ -109,7 +109,7 @@ 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(UTF_8), decodedVector.get(i)); } } } @@ -127,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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -138,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(UTF_8)); } } rawVector.setValueCount(VECTOR_LENGTH); @@ -156,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(UTF_8)); } } @@ -170,7 +170,7 @@ 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(UTF_8), decodedVector.get(i)); } } } @@ -187,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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java index a156e987c20..2a351b24a67 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java @@ -17,12 +17,12 @@ package org.apache.arrow.algorithm.dictionary; +import static java.nio.charset.StandardCharsets.UTF_8; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; @@ -51,9 +51,9 @@ public class TestSearchDictionaryEncoder { private BufferAllocator allocator; - byte[] zero = "000".getBytes(StandardCharsets.UTF_8); - byte[] one = "111".getBytes(StandardCharsets.UTF_8); - byte[] two = "222".getBytes(StandardCharsets.UTF_8); + byte[] zero = "000".getBytes(UTF_8); + byte[] one = "111".getBytes(UTF_8); + byte[] two = "222".getBytes(UTF_8); byte[][] data = new byte[][]{zero, one, two}; @@ -78,7 +78,7 @@ 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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -86,7 +86,7 @@ public void testEncodeAndDecode() { 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(UTF_8)); } rawVector.setValueCount(VECTOR_LENGTH); @@ -101,7 +101,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(UTF_8)); } // perform decoding @@ -111,7 +111,7 @@ 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(UTF_8), decodedVector.get(i)); } } } @@ -129,7 +129,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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -140,7 +140,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(UTF_8)); } } rawVector.setValueCount(VECTOR_LENGTH); @@ -159,7 +159,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(UTF_8)); } } @@ -173,7 +173,7 @@ 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(UTF_8), decodedVector.get(i)); } } } @@ -190,7 +190,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(UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchTreeBasedDictionaryBuilder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchTreeBasedDictionaryBuilder.java index d8e9edce83b..340b7e67e86 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchTreeBasedDictionaryBuilder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchTreeBasedDictionaryBuilder.java @@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.nio.charset.StandardCharsets; +import java.util.Objects; + import org.apache.arrow.algorithm.sort.DefaultVectorComparators; import org.apache.arrow.algorithm.sort.VectorValueComparator; import org.apache.arrow.memory.BufferAllocator; @@ -60,16 +63,16 @@ public void testBuildVariableWidthDictionaryWithNull() { sortedDictionary.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)); VectorValueComparator comparator = DefaultVectorComparators.createDefaultComparator(vec); SearchTreeBasedDictionaryBuilder dictionaryBuilder = @@ -83,12 +86,12 @@ public void testBuildVariableWidthDictionaryWithNull() { dictionaryBuilder.populateSortedDictionary(sortedDictionary); assertTrue(sortedDictionary.isNull(0)); - assertEquals("12", new String(sortedDictionary.get(1))); - assertEquals("abc", new String(sortedDictionary.get(2))); - assertEquals("dictionary", new String(sortedDictionary.get(3))); - assertEquals("good", new String(sortedDictionary.get(4))); - assertEquals("hello", new String(sortedDictionary.get(5))); - assertEquals("world", new String(sortedDictionary.get(6))); + assertEquals("12", new String(Objects.requireNonNull(sortedDictionary.get(1)), StandardCharsets.UTF_8)); + assertEquals("abc", new String(Objects.requireNonNull(sortedDictionary.get(2)), StandardCharsets.UTF_8)); + assertEquals("dictionary", new String(Objects.requireNonNull(sortedDictionary.get(3)), StandardCharsets.UTF_8)); + assertEquals("good", new String(Objects.requireNonNull(sortedDictionary.get(4)), StandardCharsets.UTF_8)); + assertEquals("hello", new String(Objects.requireNonNull(sortedDictionary.get(5)), StandardCharsets.UTF_8)); + assertEquals("world", new String(Objects.requireNonNull(sortedDictionary.get(6)), StandardCharsets.UTF_8)); } } @@ -105,16 +108,16 @@ public void testBuildVariableWidthDictionaryWithoutNull() { sortedDictionary.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)); VectorValueComparator comparator = DefaultVectorComparators.createDefaultComparator(vec); SearchTreeBasedDictionaryBuilder dictionaryBuilder = @@ -127,12 +130,12 @@ public void testBuildVariableWidthDictionaryWithoutNull() { dictionaryBuilder.populateSortedDictionary(sortedDictionary); - assertEquals("12", new String(sortedDictionary.get(0))); - assertEquals("abc", new String(sortedDictionary.get(1))); - assertEquals("dictionary", new String(sortedDictionary.get(2))); - assertEquals("good", new String(sortedDictionary.get(3))); - assertEquals("hello", new String(sortedDictionary.get(4))); - assertEquals("world", new String(sortedDictionary.get(5))); + assertEquals("12", new String(Objects.requireNonNull(sortedDictionary.get(0)), StandardCharsets.UTF_8)); + assertEquals("abc", new String(Objects.requireNonNull(sortedDictionary.get(1)), StandardCharsets.UTF_8)); + assertEquals("dictionary", new String(Objects.requireNonNull(sortedDictionary.get(2)), StandardCharsets.UTF_8)); + assertEquals("good", new String(Objects.requireNonNull(sortedDictionary.get(3)), StandardCharsets.UTF_8)); + assertEquals("hello", new String(Objects.requireNonNull(sortedDictionary.get(4)), StandardCharsets.UTF_8)); + assertEquals("world", new String(Objects.requireNonNull(sortedDictionary.get(5)), StandardCharsets.UTF_8)); } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/misc/TestPartialSumUtils.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/misc/TestPartialSumUtils.java index 4e2d5900f8c..630dd80b440 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/misc/TestPartialSumUtils.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/misc/TestPartialSumUtils.java @@ -67,7 +67,7 @@ public void testToPartialSumVector() { // verify results assertEquals(PARTIAL_SUM_VECTOR_LENGTH, partialSum.getValueCount()); for (int i = 0; i < partialSum.getValueCount(); i++) { - assertEquals(i * 3 + sumBase, partialSum.get(i)); + assertEquals(i * 3L + sumBase, partialSum.get(i)); } } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/rank/TestVectorRank.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/rank/TestVectorRank.java index f372a809bab..0e6627eb482 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/rank/TestVectorRank.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/rank/TestVectorRank.java @@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.nio.charset.StandardCharsets; + import org.apache.arrow.algorithm.sort.DefaultVectorComparators; import org.apache.arrow.algorithm.sort.VectorValueComparator; import org.apache.arrow.memory.BufferAllocator; @@ -89,16 +91,16 @@ public void testVariableWidthRank() { vector.allocateNew(VECTOR_LENGTH * 5, VECTOR_LENGTH); vector.setValueCount(VECTOR_LENGTH); - vector.set(0, String.valueOf(1).getBytes()); - vector.set(1, String.valueOf(5).getBytes()); - vector.set(2, String.valueOf(3).getBytes()); - vector.set(3, String.valueOf(7).getBytes()); - vector.set(4, String.valueOf(9).getBytes()); - vector.set(5, String.valueOf(8).getBytes()); - vector.set(6, String.valueOf(2).getBytes()); - vector.set(7, String.valueOf(0).getBytes()); - vector.set(8, String.valueOf(4).getBytes()); - vector.set(9, String.valueOf(6).getBytes()); + vector.set(0, String.valueOf(1).getBytes(StandardCharsets.UTF_8)); + vector.set(1, String.valueOf(5).getBytes(StandardCharsets.UTF_8)); + vector.set(2, String.valueOf(3).getBytes(StandardCharsets.UTF_8)); + vector.set(3, String.valueOf(7).getBytes(StandardCharsets.UTF_8)); + vector.set(4, String.valueOf(9).getBytes(StandardCharsets.UTF_8)); + vector.set(5, String.valueOf(8).getBytes(StandardCharsets.UTF_8)); + vector.set(6, String.valueOf(2).getBytes(StandardCharsets.UTF_8)); + vector.set(7, String.valueOf(0).getBytes(StandardCharsets.UTF_8)); + vector.set(8, String.valueOf(4).getBytes(StandardCharsets.UTF_8)); + vector.set(9, String.valueOf(6).getBytes(StandardCharsets.UTF_8)); VectorValueComparator comparator = DefaultVectorComparators.createDefaultComparator(vector); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java index 767935aaa4b..9ccecfa84a7 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -130,8 +131,8 @@ public void testParallelStringSearch() throws ExecutionException, InterruptedExc : DefaultVectorComparators.createDefaultComparator(targetVector); for (int i = 0; i < VECTOR_LENGTH; i++) { - targetVector.setSafe(i, String.valueOf(i).getBytes()); - keyVector.setSafe(i, String.valueOf(i * 2).getBytes()); + targetVector.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); + keyVector.setSafe(i, String.valueOf(i * 2).getBytes(StandardCharsets.UTF_8)); } targetVector.setValueCount(VECTOR_LENGTH); keyVector.setValueCount(VECTOR_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java index d7659dc4cfa..18f4fa0355f 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java @@ -81,7 +81,7 @@ public void testGetLowerBounds() { VectorValueComparator comparator = DefaultVectorComparators.createDefaultComparator(intVector); for (int i = 0; i < maxValue; i++) { int result = VectorRangeSearcher.getFirstMatch(intVector, comparator, intVector, i * repeat); - assertEquals(i * repeat, result); + assertEquals(i * ((long) repeat), result); } } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorSearcher.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorSearcher.java index 2847ddbb8ad..32fa10bbd98 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorSearcher.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorSearcher.java @@ -20,6 +20,8 @@ import static org.apache.arrow.vector.complex.BaseRepeatedValueVector.OFFSET_WIDTH; import static org.junit.Assert.assertEquals; +import java.nio.charset.StandardCharsets; + import org.apache.arrow.algorithm.sort.DefaultVectorComparators; import org.apache.arrow.algorithm.sort.VectorValueComparator; import org.apache.arrow.memory.BufferAllocator; @@ -142,7 +144,7 @@ public void testBinarySearchVarChar() { rawVector.set(i, content); } } - negVector.set(0, "abcd".getBytes()); + negVector.set(0, "abcd".getBytes(StandardCharsets.UTF_8)); // do search VectorValueComparator comparator = @@ -181,7 +183,7 @@ public void testLinearSearchVarChar() { rawVector.set(i, content); } } - negVector.set(0, "abcd".getBytes()); + negVector.set(0, "abcd".getBytes(StandardCharsets.UTF_8)); // do search VectorValueComparator comparator = diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java index cac9933cc0b..f7539e714f1 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java @@ -17,6 +17,8 @@ package org.apache.arrow.algorithm.sort; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; @@ -67,9 +69,9 @@ public void testCompareVectorSchemaRoot() { for (int i = 0; i < vectorLength; i++) { intVec1.set(i, i); - strVec1.set(i, new String("a" + i).getBytes()); + strVec1.set(i, ("a" + i).getBytes(UTF_8)); intVec2.set(i, i); - strVec2.set(i, new String("a5").getBytes()); + strVec2.set(i, "a5".getBytes(UTF_8)); } VectorValueComparator innerComparator1 = @@ -86,7 +88,7 @@ public void testCompareVectorSchemaRoot() { // verify results // both elements are equal, the result is equal - assertTrue(comparator.compare(5, 5) == 0); + assertEquals(0, comparator.compare(5, 5)); // the first element being equal, the second is smaller, and the result is smaller assertTrue(comparator.compare(1, 1) < 0); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestDefaultVectorComparator.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestDefaultVectorComparator.java index 43c634b7647..c40854fb174 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestDefaultVectorComparator.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestDefaultVectorComparator.java @@ -65,6 +65,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; /** * Test cases for {@link DefaultVectorComparators}. @@ -258,7 +259,8 @@ public void testCompareUInt2() { vec.allocateNew(10); ValueVectorDataPopulator.setVector( - vec, null, (char) -2, (char) -1, (char) 0, (char) 1, (char) 2, (char) -2, null, + vec, null, (char) (Character.MAX_VALUE - 1), Character.MAX_VALUE, (char) 0, (char) 1, + (char) 2, (char) (Character.MAX_VALUE - 1), null, '\u7FFF', // value for the max 16-byte signed integer '\u8000' // value for the min 16-byte signed integer ); @@ -272,8 +274,8 @@ public void testCompareUInt2() { assertTrue(comparator.compare(1, 3) > 0); assertTrue(comparator.compare(2, 5) > 0); assertTrue(comparator.compare(4, 5) < 0); - assertTrue(comparator.compare(1, 6) == 0); - assertTrue(comparator.compare(0, 7) == 0); + Assertions.assertEquals(0, comparator.compare(1, 6)); + Assertions.assertEquals(0, comparator.compare(0, 7)); assertTrue(comparator.compare(8, 9) < 0); assertTrue(comparator.compare(4, 8) < 0); assertTrue(comparator.compare(5, 9) < 0); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java index ba2a341bf44..80c72b4e21a 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java @@ -131,37 +131,37 @@ public static Collection getParameters() { for (boolean inPlace : new boolean[] {true, false}) { params.add(new Object[] { length, nullFrac, inPlace, "TinyIntVector", - (Function) (allocator -> new TinyIntVector("vector", allocator)), + (Function) allocator -> new TinyIntVector("vector", allocator), TestSortingUtil.TINY_INT_GENERATOR }); params.add(new Object[] { length, nullFrac, inPlace, "SmallIntVector", - (Function) (allocator -> new SmallIntVector("vector", allocator)), + (Function) allocator -> new SmallIntVector("vector", allocator), TestSortingUtil.SMALL_INT_GENERATOR }); params.add(new Object[] { length, nullFrac, inPlace, "IntVector", - (Function) (allocator -> new IntVector("vector", allocator)), + (Function) allocator -> new IntVector("vector", allocator), TestSortingUtil.INT_GENERATOR }); params.add(new Object[] { length, nullFrac, inPlace, "BigIntVector", - (Function) (allocator -> new BigIntVector("vector", allocator)), + (Function) allocator -> new BigIntVector("vector", allocator), TestSortingUtil.LONG_GENERATOR }); params.add(new Object[] { length, nullFrac, inPlace, "Float4Vector", - (Function) (allocator -> new Float4Vector("vector", allocator)), + (Function) allocator -> new Float4Vector("vector", allocator), TestSortingUtil.FLOAT_GENERATOR }); params.add(new Object[] { length, nullFrac, inPlace, "Float8Vector", - (Function) (allocator -> new Float8Vector("vector", allocator)), + (Function) allocator -> new Float8Vector("vector", allocator), TestSortingUtil.DOUBLE_GENERATOR }); } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java index ea86551061d..c6c17f1c845 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java @@ -17,6 +17,7 @@ package org.apache.arrow.algorithm.sort; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.Array; @@ -122,7 +123,7 @@ static String generateRandomString(int length) { str[i] = (byte) (r % (upper - lower + 1) + lower); } - return new String(str); + return new String(str, UTF_8); } /** diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java index 07419359427..0bf1cc6a702 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java @@ -17,15 +17,19 @@ package org.apache.arrow.algorithm.sort; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.Objects; + import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.VarCharVector; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; /** * Test cases for {@link StableVectorComparator}. @@ -51,11 +55,11 @@ public void testCompare() { vec.setValueCount(10); // fill data to sort - vec.set(0, "ba".getBytes()); - vec.set(1, "abc".getBytes()); - vec.set(2, "aa".getBytes()); - vec.set(3, "abc".getBytes()); - vec.set(4, "a".getBytes()); + vec.set(0, "ba".getBytes(UTF_8)); + vec.set(1, "abc".getBytes(UTF_8)); + vec.set(2, "aa".getBytes(UTF_8)); + vec.set(3, "abc".getBytes(UTF_8)); + vec.set(4, "a".getBytes(UTF_8)); VectorValueComparator comparator = new TestVarCharSorter(); VectorValueComparator stableComparator = new StableVectorComparator<>(comparator); @@ -66,7 +70,7 @@ public void testCompare() { assertTrue(stableComparator.compare(2, 3) < 0); assertTrue(stableComparator.compare(1, 3) < 0); assertTrue(stableComparator.compare(3, 1) > 0); - assertTrue(stableComparator.compare(3, 3) == 0); + Assertions.assertEquals(0, stableComparator.compare(3, 3)); } } @@ -77,16 +81,16 @@ public void testStableSortString() { vec.setValueCount(10); // fill data to sort - vec.set(0, "a".getBytes()); - vec.set(1, "abc".getBytes()); - vec.set(2, "aa".getBytes()); - vec.set(3, "a1".getBytes()); - vec.set(4, "abcdefg".getBytes()); - vec.set(5, "accc".getBytes()); - vec.set(6, "afds".getBytes()); - vec.set(7, "0".getBytes()); - vec.set(8, "01".getBytes()); - vec.set(9, "0c".getBytes()); + vec.set(0, "a".getBytes(UTF_8)); + vec.set(1, "abc".getBytes(UTF_8)); + vec.set(2, "aa".getBytes(UTF_8)); + vec.set(3, "a1".getBytes(UTF_8)); + vec.set(4, "abcdefg".getBytes(UTF_8)); + vec.set(5, "accc".getBytes(UTF_8)); + vec.set(6, "afds".getBytes(UTF_8)); + vec.set(7, "0".getBytes(UTF_8)); + vec.set(8, "01".getBytes(UTF_8)); + vec.set(9, "0c".getBytes(UTF_8)); // sort the vector VariableWidthOutOfPlaceVectorSorter sorter = new VariableWidthOutOfPlaceVectorSorter(); @@ -103,16 +107,16 @@ public void testStableSortString() { // verify results // the results are stable - assertEquals("0", new String(sortedVec.get(0))); - assertEquals("01", new String(sortedVec.get(1))); - assertEquals("0c", new String(sortedVec.get(2))); - assertEquals("a", new String(sortedVec.get(3))); - assertEquals("abc", new String(sortedVec.get(4))); - assertEquals("aa", new String(sortedVec.get(5))); - assertEquals("a1", new String(sortedVec.get(6))); - assertEquals("abcdefg", new String(sortedVec.get(7))); - assertEquals("accc", new String(sortedVec.get(8))); - assertEquals("afds", new String(sortedVec.get(9))); + assertEquals("0", new String(Objects.requireNonNull(sortedVec.get(0)), UTF_8)); + assertEquals("01", new String(Objects.requireNonNull(sortedVec.get(1)), UTF_8)); + assertEquals("0c", new String(Objects.requireNonNull(sortedVec.get(2)), UTF_8)); + assertEquals("a", new String(Objects.requireNonNull(sortedVec.get(3)), UTF_8)); + assertEquals("abc", new String(Objects.requireNonNull(sortedVec.get(4)), UTF_8)); + assertEquals("aa", new String(Objects.requireNonNull(sortedVec.get(5)), UTF_8)); + assertEquals("a1", new String(Objects.requireNonNull(sortedVec.get(6)), UTF_8)); + assertEquals("abcdefg", new String(Objects.requireNonNull(sortedVec.get(7)), UTF_8)); + assertEquals("accc", new String(Objects.requireNonNull(sortedVec.get(8)), UTF_8)); + assertEquals("afds", new String(Objects.requireNonNull(sortedVec.get(9)), UTF_8)); } } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java index 8f4e3b8e194..2486034f1fa 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java @@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +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.BaseVariableWidthVector; @@ -62,16 +65,16 @@ public void testSortString() { vec.setValueCount(10); // fill data to sort - 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, "yes".getBytes()); + vec.set(7, "hello".getBytes(StandardCharsets.UTF_8)); + vec.set(8, "good".getBytes(StandardCharsets.UTF_8)); + vec.set(9, "yes".getBytes(StandardCharsets.UTF_8)); // sort the vector OutOfPlaceVectorSorter sorter = getSorter(); @@ -93,14 +96,14 @@ public void testSortString() { assertTrue(sortedVec.isNull(0)); assertTrue(sortedVec.isNull(1)); - assertEquals("12", new String(sortedVec.get(2))); - assertEquals("abc", new String(sortedVec.get(3))); - assertEquals("dictionary", new String(sortedVec.get(4))); - assertEquals("good", new String(sortedVec.get(5))); - assertEquals("hello", new String(sortedVec.get(6))); - assertEquals("hello", new String(sortedVec.get(7))); - assertEquals("world", new String(sortedVec.get(8))); - assertEquals("yes", new String(sortedVec.get(9))); + assertEquals("12", new String(Objects.requireNonNull(sortedVec.get(2)), StandardCharsets.UTF_8)); + assertEquals("abc", new String(Objects.requireNonNull(sortedVec.get(3)), StandardCharsets.UTF_8)); + assertEquals("dictionary", new String(Objects.requireNonNull(sortedVec.get(4)), StandardCharsets.UTF_8)); + assertEquals("good", new String(Objects.requireNonNull(sortedVec.get(5)), StandardCharsets.UTF_8)); + assertEquals("hello", new String(Objects.requireNonNull(sortedVec.get(6)), StandardCharsets.UTF_8)); + assertEquals("hello", new String(Objects.requireNonNull(sortedVec.get(7)), StandardCharsets.UTF_8)); + assertEquals("world", new String(Objects.requireNonNull(sortedVec.get(8)), StandardCharsets.UTF_8)); + assertEquals("yes", new String(Objects.requireNonNull(sortedVec.get(9)), StandardCharsets.UTF_8)); sortedVec.close(); } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java index 068fe8b69a8..46f92dbb10b 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java @@ -17,6 +17,7 @@ package org.apache.arrow.algorithm.sort; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -94,7 +95,7 @@ void sortOutOfPlace() { VectorValueComparator comparator = DefaultVectorComparators.createDefaultComparator(vector); try (V sortedVec = (V) vector.getField().getFieldType().createNewSingleVector("", allocator, null)) { - int dataSize = vector.getOffsetBuffer().getInt(vector.getValueCount() * 4); + int dataSize = vector.getOffsetBuffer().getInt(vector.getValueCount() * 4L); sortedVec.allocateNew(dataSize, vector.getValueCount()); sortedVec.setValueCount(vector.getValueCount()); @@ -113,7 +114,7 @@ public static Collection getParameters() { for (double nullFrac : NULL_FRACTIONS) { params.add(new Object[]{ length, nullFrac, "VarCharVector", - (Function) (allocator -> new VarCharVector("vector", allocator)), + (Function) allocator -> new VarCharVector("vector", allocator), TestSortingUtil.STRING_GENERATOR }); } @@ -130,7 +131,7 @@ public static void verifyResults(V vector, String[] expe if (expected[i] == null) { assertTrue(vector.isNull(i)); } else { - assertArrayEquals(((Text) vector.getObject(i)).getBytes(), expected[i].getBytes()); + assertArrayEquals(((Text) vector.getObject(i)).getBytes(), expected[i].getBytes(UTF_8)); } } } @@ -151,8 +152,8 @@ public int compare(String str1, String str2) { return str1 == null ? -1 : 1; } - byte[] bytes1 = str1.getBytes(); - byte[] bytes2 = str2.getBytes(); + byte[] bytes1 = str1.getBytes(UTF_8); + byte[] bytes2 = str2.getBytes(UTF_8); for (int i = 0; i < bytes1.length && i < bytes2.length; i++) { if (bytes1[i] != bytes2[i]) { From 64a2e6d3987f7d92b9d3655cb3a8651b67a0565a Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 10 Jan 2024 13:33:09 +0530 Subject: [PATCH 11/23] fixing warnings v12: all tools --- .../src/main/java/org/apache/arrow/tools/FileRoundtrip.java | 6 ++---- .../java/org/apache/arrow/tools/ArrowFileTestFixtures.java | 2 -- .../test/java/org/apache/arrow/tools/EchoServerTest.java | 1 - .../test/java/org/apache/arrow/tools/TestFileRoundtrip.java | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/java/tools/src/main/java/org/apache/arrow/tools/FileRoundtrip.java b/java/tools/src/main/java/org/apache/arrow/tools/FileRoundtrip.java index c49b04c8558..1201d0f7605 100644 --- a/java/tools/src/main/java/org/apache/arrow/tools/FileRoundtrip.java +++ b/java/tools/src/main/java/org/apache/arrow/tools/FileRoundtrip.java @@ -43,11 +43,9 @@ public class FileRoundtrip { private static final Logger LOGGER = LoggerFactory.getLogger(FileRoundtrip.class); private final Options options; - private final PrintStream out; private final PrintStream err; - FileRoundtrip(PrintStream out, PrintStream err) { - this.out = out; + FileRoundtrip(PrintStream err) { this.err = err; this.options = new Options(); this.options.addOption("i", "in", true, "input file"); @@ -56,7 +54,7 @@ public class FileRoundtrip { } public static void main(String[] args) { - System.exit(new FileRoundtrip(System.out, System.err).run(args)); + System.exit(new FileRoundtrip(System.err).run(args)); } private File validateFile(String type, String fileName) { diff --git a/java/tools/src/test/java/org/apache/arrow/tools/ArrowFileTestFixtures.java b/java/tools/src/test/java/org/apache/arrow/tools/ArrowFileTestFixtures.java index 178a0834fa4..1bc7ead7b73 100644 --- a/java/tools/src/test/java/org/apache/arrow/tools/ArrowFileTestFixtures.java +++ b/java/tools/src/test/java/org/apache/arrow/tools/ArrowFileTestFixtures.java @@ -35,7 +35,6 @@ import org.apache.arrow.vector.ipc.ArrowFileReader; import org.apache.arrow.vector.ipc.ArrowFileWriter; import org.apache.arrow.vector.ipc.message.ArrowBlock; -import org.apache.arrow.vector.types.pojo.Schema; import org.junit.Assert; public class ArrowFileTestFixtures { @@ -63,7 +62,6 @@ static void validateOutput(File testOutFile, BufferAllocator allocator) throws E ArrowFileReader arrowReader = new ArrowFileReader(fileInputStream.getChannel(), readerAllocator)) { VectorSchemaRoot root = arrowReader.getVectorSchemaRoot(); - Schema schema = root.getSchema(); for (ArrowBlock rbBlock : arrowReader.getRecordBlocks()) { if (!arrowReader.loadRecordBatch(rbBlock)) { throw new IOException("Expected to read record batch"); diff --git a/java/tools/src/test/java/org/apache/arrow/tools/EchoServerTest.java b/java/tools/src/test/java/org/apache/arrow/tools/EchoServerTest.java index 714cb416bf9..9cf893ee5c2 100644 --- a/java/tools/src/test/java/org/apache/arrow/tools/EchoServerTest.java +++ b/java/tools/src/test/java/org/apache/arrow/tools/EchoServerTest.java @@ -142,7 +142,6 @@ public void basicTest() throws InterruptedException, IOException { Collections.emptyList()); TinyIntVector vector = new TinyIntVector("testField", FieldType.nullable(TINYINT.getType()), alloc); - Schema schema = new Schema(asList(field)); // Try an empty stream, just the header. testEchoServer(serverPort, field, vector, 0); diff --git a/java/tools/src/test/java/org/apache/arrow/tools/TestFileRoundtrip.java b/java/tools/src/test/java/org/apache/arrow/tools/TestFileRoundtrip.java index ddac6f79384..a5d6c9658fd 100644 --- a/java/tools/src/test/java/org/apache/arrow/tools/TestFileRoundtrip.java +++ b/java/tools/src/test/java/org/apache/arrow/tools/TestFileRoundtrip.java @@ -56,7 +56,7 @@ public void test() throws Exception { writeInput(testInFile, allocator); String[] args = {"-i", testInFile.getAbsolutePath(), "-o", testOutFile.getAbsolutePath()}; - int result = new FileRoundtrip(System.out, System.err).run(args); + int result = new FileRoundtrip(System.err).run(args); assertEquals(0, result); validateOutput(testOutFile, allocator); From 6ffdede5cc7263761126e1f17951640142d89fc5 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 10 Jan 2024 13:35:31 +0530 Subject: [PATCH 12/23] fixing warnings v13: all compression --- .../org/apache/arrow/compression/TestCompressionCodec.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/compression/src/test/java/org/apache/arrow/compression/TestCompressionCodec.java b/java/compression/src/test/java/org/apache/arrow/compression/TestCompressionCodec.java index 01156fa2b0e..5fff4fafd67 100644 --- a/java/compression/src/test/java/org/apache/arrow/compression/TestCompressionCodec.java +++ b/java/compression/src/test/java/org/apache/arrow/compression/TestCompressionCodec.java @@ -175,7 +175,7 @@ void testCompressVariableWidthBuffers(int vectorLength, CompressionCodec codec) if (i % 10 == 0) { origVec.setNull(i); } else { - origVec.setSafe(i, String.valueOf(i).getBytes()); + origVec.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } } origVec.setValueCount(vectorLength); @@ -199,7 +199,7 @@ void testCompressVariableWidthBuffers(int vectorLength, CompressionCodec codec) if (i % 10 == 0) { assertTrue(newVec.isNull(i)); } else { - assertArrayEquals(String.valueOf(i).getBytes(), newVec.get(i)); + assertArrayEquals(String.valueOf(i).getBytes(StandardCharsets.UTF_8), newVec.get(i)); } } From 16c954a1080e862fc3d67e7d80c47cb45211bd7f Mon Sep 17 00:00:00 2001 From: vibhatha Date: Thu, 11 Jan 2024 12:45:04 +0530 Subject: [PATCH 13/23] fixing warnings v14: vector s1 --- java/pom.xml | 11 ++++++++ java/vector/pom.xml | 13 ++++++++++ .../arrow/vector/BaseFixedWidthVector.java | 9 +++++-- .../vector/BaseLargeVariableWidthVector.java | 10 +++++++ .../apache/arrow/vector/BaseValueVector.java | 6 ++--- .../arrow/vector/BaseVariableWidthVector.java | 21 +++++++++++---- .../org/apache/arrow/vector/BufferLayout.java | 2 +- .../org/apache/arrow/vector/TypeLayout.java | 5 ++-- .../org/apache/arrow/vector/UInt4Vector.java | 1 + .../complex/BaseRepeatedValueVector.java | 10 +++---- .../arrow/vector/complex/ListVector.java | 1 + .../arrow/vector/complex/StructVector.java | 26 +++++++++++-------- .../arrow/vector/types/IntervalUnit.java | 2 +- .../vector/types/pojo/DictionaryEncoding.java | 2 +- .../apache/arrow/vector/types/pojo/Field.java | 16 +++++++----- .../arrow/vector/types/pojo/Schema.java | 7 +++-- .../org/apache/arrow/vector/util/Text.java | 6 +++-- 17 files changed, 105 insertions(+), 43 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index 3951f1c1bc8..dd0a7037cf6 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -45,6 +45,7 @@ true 9+181-r4173-1 2.24.0 + 2.24.0 3.11.0 5.5.0 5.2.0 @@ -899,6 +900,11 @@ error_prone_core 2.10.0 + + com.google.errorprone + error_prone_annotations + 2.10.0 + @@ -943,6 +949,11 @@ error_prone_core ${error_prone_core.version} + + com.google.errorprone + error_prone_annotations + ${error_prone_annotations.version} + diff --git a/java/vector/pom.xml b/java/vector/pom.xml index dc453963b62..e6a71411fc4 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -79,6 +79,11 @@ eclipse-collections 11.1.0 + + com.google.errorprone + error_prone_annotations + 2.23.0 + @@ -212,6 +217,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java index 90229460111..c456c625389 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java @@ -110,7 +110,7 @@ public String getName() { */ @Override public long getValidityBufferAddress() { - return (validityBuffer.memoryAddress()); + return validityBuffer.memoryAddress(); } /** @@ -120,7 +120,7 @@ public long getValidityBufferAddress() { */ @Override public long getDataBufferAddress() { - return (valueBuffer.memoryAddress()); + return valueBuffer.memoryAddress(); } /** @@ -298,6 +298,7 @@ public boolean allocateNewSafe() { * @param valueCount the desired number of elements in the vector * @throws org.apache.arrow.memory.OutOfMemoryException on error */ + @Override public void allocateNew(int valueCount) { computeAndCheckBufferSize(valueCount); @@ -521,6 +522,7 @@ public void loadFieldBuffers(ArrowFieldNode fieldNode, List ownBuffers * * @return the inner buffers. */ + @Override public List getFieldBuffers() { List result = new ArrayList<>(2); setReaderAndWriterIndex(); @@ -597,6 +599,7 @@ public TransferPair getTransferPair(BufferAllocator allocator) { * @param allocator allocator for the target vector * @return TransferPair */ + @Override public abstract TransferPair getTransferPair(String ref, BufferAllocator allocator); /** @@ -605,6 +608,7 @@ public TransferPair getTransferPair(BufferAllocator allocator) { * @param allocator allocator for the target vector * @return TransferPair */ + @Override public abstract TransferPair getTransferPair(Field field, BufferAllocator allocator); /** @@ -911,6 +915,7 @@ public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) { * * @param index position of element */ + @Override public void setNull(int index) { handleSafe(index); // not really needed to set the bit to 0 as long as diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java index a77278138f2..c239edbcc3c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java @@ -228,6 +228,7 @@ private void initOffsetBuffer() { * Reset the vector to initial state. Same as {@link #zeroVector()}. * Note that this method doesn't release any memory. */ + @Override public void reset() { zeroVector(); lastSet = -1; @@ -318,6 +319,7 @@ public void loadFieldBuffers(ArrowFieldNode fieldNode, List ownBuffers * Get the buffers belonging to this vector. * @return the inner buffers. */ + @Override public List getFieldBuffers() { // before flight/IPC, we must bring the vector to a consistent state. // this is because, it is possible that the offset buffers of some trailing values @@ -471,6 +473,7 @@ private void allocateValidityBuffer(final long size) { * Resize the vector to increase the capacity. The internal behavior is to * double the current value capacity. */ + @Override public void reAlloc() { reallocDataBuffer(); reallocValidityAndOffsetBuffers(); @@ -691,6 +694,7 @@ public TransferPair getTransferPair(BufferAllocator allocator) { * @param allocator allocator for the target vector * @return TransferPair */ + @Override public abstract TransferPair getTransferPair(String ref, BufferAllocator allocator); /** @@ -699,6 +703,7 @@ public TransferPair getTransferPair(BufferAllocator allocator) { * @param allocator allocator for the target vector * @return TransferPair */ + @Override public abstract TransferPair getTransferPair(Field field, BufferAllocator allocator); /** @@ -835,6 +840,7 @@ private void splitAndTransferValidityBuffer(int startIndex, int length, * * @return the number of null elements. */ + @Override public int getNullCount() { return BitVectorHelper.getNullCount(validityBuffer, valueCount); } @@ -856,6 +862,7 @@ public boolean isSafe(int index) { * @param index position of element * @return true if element at given index is null */ + @Override public boolean isNull(int index) { return (isSet(index) == 0); } @@ -879,6 +886,7 @@ public int isSet(int index) { * * @return valueCount for the vector */ + @Override public int getValueCount() { return valueCount; } @@ -888,6 +896,7 @@ public int getValueCount() { * * @param valueCount value count */ + @Override public void setValueCount(int valueCount) { assert valueCount >= 0; this.valueCount = valueCount; @@ -1091,6 +1100,7 @@ public void setSafe(int index, ByteBuffer value, int start, int length) { * * @param index position of element */ + @Override public void setNull(int index) { // We need to check and realloc both validity and offset buffer while (index >= getValueCapacity()) { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java index 679e5d06c01..070919c3567 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java @@ -28,15 +28,12 @@ import org.apache.arrow.vector.util.DataSizeRoundingUtil; import org.apache.arrow.vector.util.TransferPair; import org.apache.arrow.vector.util.ValueVectorUtility; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Base class for other Arrow Vector Types. Provides basic functionality around * memory management. */ public abstract class BaseValueVector implements ValueVector { - private static final Logger logger = LoggerFactory.getLogger(BaseValueVector.class); public static final String MAX_ALLOCATION_SIZE_PROPERTY = "arrow.vector.max_allocation_bytes"; public static final long MAX_ALLOCATION_SIZE = Long.getLong(MAX_ALLOCATION_SIZE_PROPERTY, Long.MAX_VALUE); @@ -160,6 +157,7 @@ long computeCombinedBufferSize(int valueCount, int typeWidth) { * * @return Concrete instance of FieldReader by using double-checked locking. */ + @Override public FieldReader getReader() { FieldReader reader = fieldReader; @@ -178,7 +176,7 @@ public FieldReader getReader() { /** * Container for primitive vectors (1 for the validity bit-mask and one to hold the values). */ - class DataAndValidityBuffers { + static class DataAndValidityBuffers { private ArrowBuf dataBuf; private ArrowBuf validityBuf; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java index 46bc9815f03..4cf495a349f 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java @@ -247,6 +247,7 @@ private void initOffsetBuffer() { * Reset the vector to initial state. Same as {@link #zeroVector()}. * Note that this method doesn't release any memory. */ + @Override public void reset() { zeroVector(); lastSet = -1; @@ -337,6 +338,7 @@ public void loadFieldBuffers(ArrowFieldNode fieldNode, List ownBuffers * Get the buffers belonging to this vector. * @return the inner buffers. */ + @Override public List getFieldBuffers() { // before flight/IPC, we must bring the vector to a consistent state. // this is because, it is possible that the offset buffers of some trailing values @@ -493,6 +495,7 @@ private void allocateValidityBuffer(final long size) { * Resize the vector to increase the capacity. The internal behavior is to * double the current value capacity. */ + @Override public void reAlloc() { reallocDataBuffer(); reallocValidityAndOffsetBuffers(); @@ -732,6 +735,7 @@ public TransferPair getTransferPair(BufferAllocator allocator) { * @param allocator allocator for the target vector * @return TransferPair */ + @Override public abstract TransferPair getTransferPair(String ref, BufferAllocator allocator); /** @@ -740,6 +744,7 @@ public TransferPair getTransferPair(BufferAllocator allocator) { * @param allocator allocator for the target vector * @return TransferPair */ + @Override public abstract TransferPair getTransferPair(Field field, BufferAllocator allocator); /** @@ -796,7 +801,8 @@ private void splitAndTransferOffsetBuffer(int startIndex, int length, BaseVariab final int dataLength = end - start; if (start == 0) { - final ArrowBuf slicedOffsetBuffer = offsetBuffer.slice(startIndex * OFFSET_WIDTH, (1 + length) * OFFSET_WIDTH); + final ArrowBuf slicedOffsetBuffer = offsetBuffer.slice(startIndex * ((long) OFFSET_WIDTH), + (1 + length) * ((long) OFFSET_WIDTH)); target.offsetBuffer = transferBuffer(slicedOffsetBuffer, target.allocator); } else { target.allocateOffsetBuffer((long) (length + 1) * OFFSET_WIDTH); @@ -883,6 +889,7 @@ private void splitAndTransferValidityBuffer(int startIndex, int length, * * @return the number of null elements. */ + @Override public int getNullCount() { return BitVectorHelper.getNullCount(validityBuffer, valueCount); } @@ -904,6 +911,7 @@ public boolean isSafe(int index) { * @param index position of element * @return true if element at given index is null */ + @Override public boolean isNull(int index) { return (isSet(index) == 0); } @@ -927,6 +935,7 @@ public int isSet(int index) { * * @return valueCount for the vector */ + @Override public int getValueCount() { return valueCount; } @@ -936,6 +945,7 @@ public int getValueCount() { * * @param valueCount value count */ + @Override public void setValueCount(int valueCount) { assert valueCount >= 0; this.valueCount = valueCount; @@ -1016,7 +1026,7 @@ public void setValueLengthSafe(int index, int length) { handleSafe(index, length); fillHoles(index); final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + length); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + length); lastSet = index; } @@ -1119,7 +1129,7 @@ public void set(int index, ByteBuffer value, int start, int length) { fillHoles(index); BitVectorHelper.setBit(validityBuffer, index); final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + length); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + length); valueBuffer.setBytes(startOffset, value, start, length); lastSet = index; } @@ -1140,7 +1150,7 @@ public void setSafe(int index, ByteBuffer value, int start, int length) { fillHoles(index); BitVectorHelper.setBit(validityBuffer, index); final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + length); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + length); valueBuffer.setBytes(startOffset, value, start, length); lastSet = index; } @@ -1150,6 +1160,7 @@ public void setSafe(int index, ByteBuffer value, int start, int length) { * * @param index position of element */ + @Override public void setNull(int index) { // We need to check and realloc both validity and offset buffer while (index >= getValueCapacity()) { @@ -1174,7 +1185,7 @@ public void set(int index, int isSet, int start, int end, ArrowBuf buffer) { fillHoles(index); BitVectorHelper.setValidityBit(validityBuffer, index, isSet); final int startOffset = offsetBuffer.getInt((long) index * OFFSET_WIDTH); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, buffer, start, dataLength); lastSet = index; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BufferLayout.java b/java/vector/src/main/java/org/apache/arrow/vector/BufferLayout.java index 09c874e3980..9725693348a 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BufferLayout.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BufferLayout.java @@ -144,7 +144,7 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof BufferLayout)) { return false; } BufferLayout other = (BufferLayout) obj; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TypeLayout.java b/java/vector/src/main/java/org/apache/arrow/vector/TypeLayout.java index 60fe2a6a6ee..ae465418cf2 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TypeLayout.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TypeLayout.java @@ -55,7 +55,7 @@ public class TypeLayout { /** - * Constructs a new {@TypeLayout} for the given arrowType. + * Constructs a new {@link TypeLayout} for the given arrowType. */ public static TypeLayout getTypeLayout(final ArrowType arrowType) { TypeLayout layout = arrowType.accept(new ArrowTypeVisitor() { @@ -421,6 +421,7 @@ public List getBufferTypes() { return types; } + @Override public String toString() { return bufferLayouts.toString(); } @@ -438,7 +439,7 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof TypeLayout)) { return false; } TypeLayout other = (TypeLayout) obj; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java index bda98b12005..f9bed0c013a 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java @@ -136,6 +136,7 @@ public void get(int index, NullableUInt4Holder holder) { * @param index position of element * @return element at given index */ + @Override public Integer getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java index 95deceb4e75..3d8859f87e5 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java @@ -54,7 +54,7 @@ public abstract class BaseRepeatedValueVector extends BaseValueVector implements public static final byte OFFSET_WIDTH = 4; protected ArrowBuf offsetBuffer; protected FieldVector vector; - protected final CallBack callBack; + protected final CallBack repeatedCallBack; protected int valueCount; protected long offsetAllocationSizeInBytes = INITIAL_VALUE_ALLOCATION * OFFSET_WIDTH; private final String name; @@ -70,7 +70,7 @@ protected BaseRepeatedValueVector(String name, BufferAllocator allocator, FieldV this.name = name; this.offsetBuffer = allocator.getEmpty(); this.vector = Preconditions.checkNotNull(vector, "data vector cannot be null"); - this.callBack = callBack; + this.repeatedCallBack = callBack; this.valueCount = 0; } @@ -313,13 +313,13 @@ public int size() { public AddOrGetResult addOrGetVector(FieldType fieldType) { boolean created = false; if (vector instanceof NullVector) { - vector = fieldType.createNewSingleVector(defaultDataVectorName, allocator, callBack); + vector = fieldType.createNewSingleVector(defaultDataVectorName, allocator, repeatedCallBack); // returned vector must have the same field created = true; - if (callBack != null && + if (repeatedCallBack != null && // not a schema change if changing from ZeroVector to ZeroVector (fieldType.getType().getTypeID() != ArrowTypeID.Null)) { - callBack.doWork(); + repeatedCallBack.doWork(); } } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java index e5a83921b31..cc68d8cb699 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java @@ -291,6 +291,7 @@ public void allocateNew() throws OutOfMemoryException { * * @return false if memory allocation fails, true otherwise. */ + @Override public boolean allocateNewSafe() { boolean success = false; try { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java index 27db1574808..ed6b7b0bdce 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java @@ -495,10 +495,9 @@ public boolean allocateNewSafe() { } finally { if (!success) { clear(); - return false; } } - return true; + return success; } private void allocateValidityBuffer(final long size) { @@ -518,12 +517,23 @@ public void reAlloc() { private void reallocValidityBuffer() { final int currentBufferCapacity = checkedCastToInt(validityBuffer.capacity()); - long newAllocationSize = currentBufferCapacity * 2; + long newAllocationSize = getNewAllocationSize(currentBufferCapacity); + + final ArrowBuf newBuf = allocator.buffer((int) newAllocationSize); + newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity); + newBuf.setZero(currentBufferCapacity, newBuf.capacity() - currentBufferCapacity); + validityBuffer.getReferenceManager().release(1); + validityBuffer = newBuf; + validityAllocationSizeInBytes = (int) newAllocationSize; + } + + private long getNewAllocationSize(int currentBufferCapacity) { + long newAllocationSize = currentBufferCapacity * 2L; if (newAllocationSize == 0) { if (validityAllocationSizeInBytes > 0) { newAllocationSize = validityAllocationSizeInBytes; } else { - newAllocationSize = BitVectorHelper.getValidityBufferSize(BaseValueVector.INITIAL_VALUE_ALLOCATION) * 2; + newAllocationSize = BitVectorHelper.getValidityBufferSize(BaseValueVector.INITIAL_VALUE_ALLOCATION) * 2L; } } newAllocationSize = CommonUtil.nextPowerOfTwo(newAllocationSize); @@ -532,13 +542,7 @@ private void reallocValidityBuffer() { if (newAllocationSize > BaseValueVector.MAX_ALLOCATION_SIZE) { throw new OversizedAllocationException("Unable to expand the buffer"); } - - final ArrowBuf newBuf = allocator.buffer((int) newAllocationSize); - newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity); - newBuf.setZero(currentBufferCapacity, newBuf.capacity() - currentBufferCapacity); - validityBuffer.getReferenceManager().release(1); - validityBuffer = newBuf; - validityAllocationSizeInBytes = (int) newAllocationSize; + return newAllocationSize; } @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/IntervalUnit.java b/java/vector/src/main/java/org/apache/arrow/vector/types/IntervalUnit.java index 1b17240d016..d2314ea7cce 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/IntervalUnit.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/IntervalUnit.java @@ -36,7 +36,7 @@ public enum IntervalUnit { } } - private short flatbufID; + private final short flatbufID; private IntervalUnit(short flatbufID) { this.flatbufID = flatbufID; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/DictionaryEncoding.java b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/DictionaryEncoding.java index 8d41b92d867..592e18826f0 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/DictionaryEncoding.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/DictionaryEncoding.java @@ -74,7 +74,7 @@ public String toString() { public boolean equals(Object o) { if (this == o) { return true; - } else if (o == null || getClass() != o.getClass()) { + } else if (!(o instanceof DictionaryEncoding)) { return false; } DictionaryEncoding that = (DictionaryEncoding) o; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java index 54c609d4a10..d3623618e7a 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java @@ -37,7 +37,6 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Collections2; import org.apache.arrow.vector.FieldVector; -import org.apache.arrow.vector.TypeLayout; import org.apache.arrow.vector.types.pojo.ArrowType.ExtensionType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,16 +92,19 @@ private Field( this(name, new FieldType(nullable, type, dictionary, convertMetadata(metadata)), children); } - private Field(String name, FieldType fieldType, List children, TypeLayout typeLayout) { + /** + * Constructs a new Field object. + * + * @param name name of the field + * @param fieldType type of the field + * @param children child fields, if any + */ + public Field(String name, FieldType fieldType, List children) { this.name = name; this.fieldType = checkNotNull(fieldType); this.children = children == null ? Collections.emptyList() : Collections2.toImmutableList(children); } - public Field(String name, FieldType fieldType, List children) { - this(name, fieldType, children, fieldType == null ? null : TypeLayout.getTypeLayout(fieldType.getType())); - } - /** * Construct a new vector of this type using the given allocator. */ @@ -279,7 +281,7 @@ public boolean equals(Object obj) { } Field that = (Field) obj; return Objects.equals(this.name, that.name) && - Objects.equals(this.isNullable(), that.isNullable()) && + this.isNullable() == that.isNullable() && Objects.equals(this.getType(), that.getType()) && Objects.equals(this.getDictionary(), that.getDictionary()) && Objects.equals(this.getMetadata(), that.getMetadata()) && diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java index dcffea0ef53..9aed357912e 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java @@ -53,6 +53,7 @@ import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream; +import com.google.errorprone.annotations.InlineMe; import com.google.flatbuffers.FlatBufferBuilder; /** @@ -95,6 +96,8 @@ public static Schema fromJSON(String json) throws IOException { * @return The deserialized schema. */ @Deprecated + @InlineMe(replacement = "Schema.convertSchema(org.apache.arrow.flatbuf.Schema.getRootAsSchema(buffer))", + imports = "org.apache.arrow.vector.types.pojo.Schema") public static Schema deserialize(ByteBuffer buffer) { return convertSchema(org.apache.arrow.flatbuf.Schema.getRootAsSchema(buffer)); } @@ -159,7 +162,7 @@ private Schema(@JsonProperty("fields") Iterable fields, /** * Private constructor to bypass automatic collection copy. - * @param unsafe a ignored argument. Its only purpose is to prevent using the constructor + * @param unsafe an ignored argument. Its only purpose is to prevent using the constructor * by accident because of type collisions (List vs Iterable). */ private Schema(boolean unsafe, List fields, Map metadata) { @@ -245,7 +248,7 @@ public int getSchema(FlatBufferBuilder builder) { /** * Returns the serialized flatbuffer bytes of the schema wrapped in a message table. - * Use {@link #deserializeMessage() to rebuild the Schema.} + * Use {@link #deserializeMessage(ByteBuffer)} to rebuild the Schema. */ public byte[] serializeAsMessage() { ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java b/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java index 5f5f5d3bd6d..ef07b9f16de 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java @@ -202,7 +202,9 @@ public int find(String what, int start) { public void set(String string) { try { ByteBuffer bb = encode(string, true); - bytes = bb.array(); + bytes = new byte[bb.remaining()]; + bb.get(bytes); + bb.position(bb.position() - bytes.length); // move it back so we can decode it length = bb.limit(); } catch (CharacterCodingException e) { throw new RuntimeException("Should not have happened ", e); @@ -210,7 +212,7 @@ public void set(String string) { } /** - * Set to a utf8 byte array. + * Set to an utf8 byte array. * * @param utf8 the byte array to initialize from */ From bdeccee261c5953f9e3a0d49ee2670de15407e7b Mon Sep 17 00:00:00 2001 From: vibhatha Date: Thu, 11 Jan 2024 16:32:34 +0530 Subject: [PATCH 14/23] fixing warnings v15: vector s2 --- java/pom.xml | 11 ------- java/vector/pom.xml | 5 --- .../org/apache/arrow/vector/BigIntVector.java | 1 + .../org/apache/arrow/vector/BitVector.java | 13 ++++---- .../apache/arrow/vector/DateDayVector.java | 1 + .../apache/arrow/vector/DateMilliVector.java | 1 + .../apache/arrow/vector/Decimal256Vector.java | 1 + .../apache/arrow/vector/DecimalVector.java | 1 + .../apache/arrow/vector/DurationVector.java | 1 + .../org/apache/arrow/vector/Float4Vector.java | 1 + .../org/apache/arrow/vector/Float8Vector.java | 1 + .../arrow/vector/GenerateSampleData.java | 4 +-- .../org/apache/arrow/vector/IntVector.java | 1 + .../arrow/vector/IntervalDayVector.java | 17 +++++----- .../vector/IntervalMonthDayNanoVector.java | 1 + .../arrow/vector/IntervalYearVector.java | 5 +-- .../arrow/vector/LargeVarBinaryVector.java | 1 + .../arrow/vector/LargeVarCharVector.java | 1 + .../apache/arrow/vector/SmallIntVector.java | 1 + .../apache/arrow/vector/TimeMicroVector.java | 1 + .../apache/arrow/vector/TimeMilliVector.java | 1 + .../apache/arrow/vector/TimeNanoVector.java | 1 + .../apache/arrow/vector/TimeSecVector.java | 1 + .../arrow/vector/TimeStampMicroTZVector.java | 1 + .../arrow/vector/TimeStampMicroVector.java | 1 + .../arrow/vector/TimeStampMilliTZVector.java | 1 + .../arrow/vector/TimeStampMilliVector.java | 1 + .../arrow/vector/TimeStampNanoTZVector.java | 1 + .../arrow/vector/TimeStampNanoVector.java | 1 + .../arrow/vector/TimeStampSecVector.java | 1 + .../apache/arrow/vector/TinyIntVector.java | 1 + .../org/apache/arrow/vector/UInt1Vector.java | 1 + .../org/apache/arrow/vector/UInt2Vector.java | 1 + .../org/apache/arrow/vector/UInt8Vector.java | 1 + .../apache/arrow/vector/VarBinaryVector.java | 11 ++++--- .../apache/arrow/vector/VarCharVector.java | 11 ++++--- .../apache/arrow/vector/VectorSchemaRoot.java | 1 + .../complex/AbstractContainerVector.java | 1 + .../vector/complex/AbstractStructVector.java | 6 ++-- .../complex/BaseRepeatedValueVector.java | 10 +++--- .../vector/complex/FixedSizeListVector.java | 12 +++---- .../arrow/vector/complex/LargeListVector.java | 24 +++++++------- .../arrow/vector/complex/ListVector.java | 32 +++++++++++-------- .../arrow/vector/complex/StructVector.java | 5 ++- .../complex/impl/AbstractBaseReader.java | 1 + .../vector/complex/impl/PromotableWriter.java | 5 ++- .../complex/impl/StructOrListWriterImpl.java | 3 +- .../impl/UnionFixedSizeListReader.java | 1 + .../complex/impl/UnionLargeListReader.java | 1 - .../vector/complex/impl/UnionListReader.java | 5 +-- .../arrow/vector/dictionary/Dictionary.java | 2 +- .../arrow/vector/table/package-info.java | 2 +- .../vector/types/FloatingPointPrecision.java | 2 +- .../arrow/vector/types/pojo/FieldType.java | 2 +- .../arrow/vector/types/pojo/Schema.java | 10 ++---- .../arrow/vector/util/MapWithOrdinalImpl.java | 9 ++---- 56 files changed, 134 insertions(+), 105 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index dd0a7037cf6..3951f1c1bc8 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -45,7 +45,6 @@ true 9+181-r4173-1 2.24.0 - 2.24.0 3.11.0 5.5.0 5.2.0 @@ -900,11 +899,6 @@ error_prone_core 2.10.0 - - com.google.errorprone - error_prone_annotations - 2.10.0 - @@ -949,11 +943,6 @@ error_prone_core ${error_prone_core.version} - - com.google.errorprone - error_prone_annotations - ${error_prone_annotations.version} - diff --git a/java/vector/pom.xml b/java/vector/pom.xml index e6a71411fc4..828ccec1a02 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -79,11 +79,6 @@ eclipse-collections 11.1.0 - - com.google.errorprone - error_prone_annotations - 2.23.0 - diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java index b0052e7e330..095d98aa265 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java @@ -129,6 +129,7 @@ public void get(int index, NullableBigIntHolder holder) { * @param index position of element * @return element at given index */ + @Override public Long getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java index 104819147b1..a34df8cf6f6 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java @@ -105,7 +105,7 @@ public MinorType getMinorType() { @Override public void setInitialCapacity(int valueCount) { final int size = getValidityBufferSizeFromCount(valueCount); - if (size * 2 > MAX_ALLOCATION_SIZE) { + if (size * 2L > MAX_ALLOCATION_SIZE) { throw new OversizedAllocationException("Requested amount of memory is more than max allowed"); } lastValueCapacity = valueCount; @@ -149,15 +149,14 @@ public int getBufferSize() { * @param length length of the split. * @param target destination vector */ + @Override public void splitAndTransferTo(int startIndex, int length, BaseFixedWidthVector target) { Preconditions.checkArgument(startIndex >= 0 && length >= 0 && startIndex + length <= valueCount, "Invalid parameters startIndex: %s, length: %s for valueCount: %s", startIndex, length, valueCount); compareTypes(target, "splitAndTransferTo"); target.clear(); - target.validityBuffer = splitAndTransferBuffer(startIndex, length, target, - validityBuffer, target.validityBuffer); - target.valueBuffer = splitAndTransferBuffer(startIndex, length, target, - valueBuffer, target.valueBuffer); + target.validityBuffer = splitAndTransferBuffer(startIndex, length, validityBuffer, target.validityBuffer); + target.valueBuffer = splitAndTransferBuffer(startIndex, length, valueBuffer, target.valueBuffer); target.refreshValueCapacity(); target.setValueCount(length); @@ -166,7 +165,6 @@ public void splitAndTransferTo(int startIndex, int length, BaseFixedWidthVector private ArrowBuf splitAndTransferBuffer( int startIndex, int length, - BaseFixedWidthVector target, ArrowBuf sourceBuffer, ArrowBuf destBuffer) { int firstByteSource = BitVectorHelper.byteIndex(startIndex); @@ -276,11 +274,12 @@ public void get(int index, NullableBitHolder holder) { * @param index position of element * @return element at given index */ + @Override public Boolean getObject(int index) { if (isSet(index) == 0) { return null; } else { - return new Boolean(getBit(index) != 0); + return getBit(index) != 0; } } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java index c99c5786058..13645d3b260 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java @@ -131,6 +131,7 @@ public void get(int index, NullableDateDayHolder holder) { * @param index position of element * @return element at given index */ + @Override public Integer getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java index 6ab8ac4eed2..1333fb0adce 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java @@ -133,6 +133,7 @@ public void get(int index, NullableDateMilliHolder holder) { * @param index position of element * @return element at given index */ + @Override public LocalDateTime getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java index fe650c7d280..931c4eea0af 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java @@ -151,6 +151,7 @@ public void get(int index, NullableDecimal256Holder holder) { * @param index position of element * @return element at given index */ + @Override public BigDecimal getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java index 7c3662c8674..eefcee837f7 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java @@ -150,6 +150,7 @@ public void get(int index, NullableDecimalHolder holder) { * @param index position of element * @return element at given index */ + @Override public BigDecimal getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java index b6abc16194b..636afef1e9f 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java @@ -143,6 +143,7 @@ public void get(int index, NullableDurationHolder holder) { * @param index position of element * @return element at given index */ + @Override public Duration getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java index 4b56a22f2d0..46f9447be29 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java @@ -131,6 +131,7 @@ public void get(int index, NullableFloat4Holder holder) { * @param index position of element * @return element at given index */ + @Override public Float getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java index 7e4fae7087b..840f9d4ba08 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java @@ -131,6 +131,7 @@ public void get(int index, NullableFloat8Holder holder) { * @param index position of element * @return element at given index */ + @Override public Double getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java b/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java index efebfd83543..6cda18a8a53 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java @@ -108,8 +108,8 @@ private static void writeTimeStampData(TimeStampVector vector, int valueCount) { } private static void writeDecimalData(DecimalVector vector, int valueCount) { - final BigDecimal even = new BigDecimal(0.0543278923); - final BigDecimal odd = new BigDecimal(2.0543278923); + final BigDecimal even = new BigDecimal("0.0543278923"); + final BigDecimal odd = new BigDecimal("2.0543278923"); for (int i = 0; i < valueCount; i++) { if (i % 2 == 0) { vector.setSafe(i, even); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java index 5c8ef440e8e..08ead148af3 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java @@ -131,6 +131,7 @@ public void get(int index, NullableIntHolder holder) { * @param index position of element * @return element at given index */ + @Override public Integer getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java index 7c0d19baa9a..f53eb37138d 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java @@ -164,6 +164,7 @@ public void get(int index, NullableIntervalDayHolder holder) { * @param index position of element * @return element at given index */ + @Override public Duration getObject(int index) { if (isSet(index) == 0) { return null; @@ -206,23 +207,23 @@ private StringBuilder getAsStringBuilderHelper(int index) { final int days = valueBuffer.getInt(startIndex); int millis = valueBuffer.getInt(startIndex + MILLISECOND_OFFSET); - final int hours = millis / (org.apache.arrow.vector.util.DateUtility.hoursToMillis); - millis = millis % (org.apache.arrow.vector.util.DateUtility.hoursToMillis); + final int hours = millis / org.apache.arrow.vector.util.DateUtility.hoursToMillis; + millis = millis % org.apache.arrow.vector.util.DateUtility.hoursToMillis; - final int minutes = millis / (org.apache.arrow.vector.util.DateUtility.minutesToMillis); - millis = millis % (org.apache.arrow.vector.util.DateUtility.minutesToMillis); + final int minutes = millis / org.apache.arrow.vector.util.DateUtility.minutesToMillis; + millis = millis % org.apache.arrow.vector.util.DateUtility.minutesToMillis; - final int seconds = millis / (org.apache.arrow.vector.util.DateUtility.secondsToMillis); - millis = millis % (org.apache.arrow.vector.util.DateUtility.secondsToMillis); + final int seconds = millis / org.apache.arrow.vector.util.DateUtility.secondsToMillis; + millis = millis % org.apache.arrow.vector.util.DateUtility.secondsToMillis; final String dayString = (Math.abs(days) == 1) ? " day " : " days "; - return (new StringBuilder() + return new StringBuilder() .append(days).append(dayString) .append(hours).append(":") .append(minutes).append(":") .append(seconds).append(".") - .append(millis)); + .append(millis); } /*----------------------------------------------------------------* diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java index fc0aa9d27b1..716af6fec9c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java @@ -186,6 +186,7 @@ public void get(int index, NullableIntervalMonthDayNanoHolder holder) { * @param index position of element * @return element at given index */ + @Override public PeriodDuration getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java index 7fe572f3ff1..c5f384604aa 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java @@ -147,6 +147,7 @@ public void get(int index, NullableIntervalYearHolder holder) { * @param index position of element * @return element at given index */ + @Override public Period getObject(int index) { if (isSet(index) == 0) { return null; @@ -181,11 +182,11 @@ private StringBuilder getAsStringBuilderHelper(int index) { final String yearString = (Math.abs(years) == 1) ? " year " : " years "; final String monthString = (Math.abs(months) == 1) ? " month " : " months "; - return (new StringBuilder() + return new StringBuilder() .append(years) .append(yearString) .append(months) - .append(monthString)); + .append(monthString); } /*----------------------------------------------------------------* diff --git a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java index 0750f68f4f7..8560ba3a68b 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java @@ -131,6 +131,7 @@ public void read(int index, ReusableBuffer buffer) { * @param index position of element to get * @return byte array for non-null element, null otherwise */ + @Override public byte[] getObject(int index) { return get(index); } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java index 6f08fcb81fe..df424c87488 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java @@ -121,6 +121,7 @@ public byte[] get(int index) { * @param index position of element to get * @return Text object for non-null element, null otherwise */ + @Override public Text getObject(int index) { assert index >= 0; if (NULL_CHECKING_ENABLED && isSet(index) == 0) { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java index 518ee707396..37a6fe11040 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java @@ -131,6 +131,7 @@ public void get(int index, NullableSmallIntHolder holder) { * @param index position of element * @return element at given index */ + @Override public Short getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java index 86738cd221e..c463dc36336 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java @@ -131,6 +131,7 @@ public void get(int index, NullableTimeMicroHolder holder) { * @param index position of element * @return element at given index */ + @Override public Long getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java index 480add91097..1e745d9b992 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java @@ -133,6 +133,7 @@ public void get(int index, NullableTimeMilliHolder holder) { * @param index position of element * @return element at given index */ + @Override public LocalDateTime getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java index 82609cdc446..426e865a5c1 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java @@ -131,6 +131,7 @@ public void get(int index, NullableTimeNanoHolder holder) { * @param index position of element * @return element at given index */ + @Override public Long getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java index 9b7614e55b6..c760ed29e04 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java @@ -131,6 +131,7 @@ public void get(int index, NullableTimeSecHolder holder) { * @param index position of element * @return element at given index */ + @Override public Integer getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java index a37b444d1a3..b515f8e2c83 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java @@ -133,6 +133,7 @@ public void get(int index, NullableTimeStampMicroTZHolder holder) { * @param index position of element * @return element at given index */ + @Override public Long getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java index 88ce27a187e..2f65921f22b 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java @@ -119,6 +119,7 @@ public void get(int index, NullableTimeStampMicroHolder holder) { * @param index position of element * @return element at given index */ + @Override public LocalDateTime getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java index 775594ceea6..d0293099432 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java @@ -133,6 +133,7 @@ public void get(int index, NullableTimeStampMilliTZHolder holder) { * @param index position of element * @return element at given index */ + @Override public Long getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java index a42773269f8..96440fd5ac3 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java @@ -119,6 +119,7 @@ public void get(int index, NullableTimeStampMilliHolder holder) { * @param index position of element * @return element at given index */ + @Override public LocalDateTime getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java index af43cf6fc9b..f93ec9b24c4 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java @@ -133,6 +133,7 @@ public void get(int index, NullableTimeStampNanoTZHolder holder) { * @param index position of element * @return element at given index */ + @Override public Long getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java index 7b02b1c87d3..723e62f8d6e 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java @@ -119,6 +119,7 @@ public void get(int index, NullableTimeStampNanoHolder holder) { * @param index position of element * @return element at given index */ + @Override public LocalDateTime getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java index 1e249140335..2de01fd52e4 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java @@ -119,6 +119,7 @@ public void get(int index, NullableTimeStampSecHolder holder) { * @param index position of element * @return element at given index */ + @Override public LocalDateTime getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java index 4c4eee1342f..e9ea59298d0 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java @@ -131,6 +131,7 @@ public void get(int index, NullableTinyIntHolder holder) { * @param index position of element * @return element at given index */ + @Override public Byte getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java index 777df3fb1ef..fcb04eaf088 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java @@ -136,6 +136,7 @@ public void get(int index, NullableUInt1Holder holder) { * @param index position of element * @return element at given index */ + @Override public Byte getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java index e5b95be191d..a9708a4faa9 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java @@ -127,6 +127,7 @@ public void get(int index, NullableUInt2Holder holder) { * @param index position of element * @return element at given index */ + @Override public Character getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java index 5e7c18902f0..a3e16b5e30d 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java @@ -136,6 +136,7 @@ public void get(int index, NullableUInt8Holder holder) { * @param index position of element * @return element at given index */ + @Override public Long getObject(int index) { if (isSet(index) == 0) { return null; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java b/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java index 87790c1168b..ab67ebad965 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java @@ -132,6 +132,7 @@ public void read(int index, ReusableBuffer buffer) { * @param index position of element to get * @return byte array for non-null element, null otherwise */ + @Override public byte[] getObject(int index) { return get(index); } @@ -176,7 +177,7 @@ public void set(int index, VarBinaryHolder holder) { BitVectorHelper.setBit(validityBuffer, index); final int dataLength = holder.end - holder.start; final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); lastSet = index; } @@ -196,7 +197,7 @@ public void setSafe(int index, VarBinaryHolder holder) { fillHoles(index); BitVectorHelper.setBit(validityBuffer, index); final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); lastSet = index; } @@ -215,10 +216,10 @@ public void set(int index, NullableVarBinaryHolder holder) { final int startOffset = getStartOffset(index); if (holder.isSet != 0) { final int dataLength = holder.end - holder.start; - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); } else { - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset); } lastSet = index; } @@ -238,7 +239,7 @@ public void setSafe(int index, NullableVarBinaryHolder holder) { handleSafe(index, dataLength); fillHoles(index); final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); } else { fillEmpties(index + 1); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java b/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java index 7350dc99bbd..c6d5a7090bc 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java @@ -118,6 +118,7 @@ public byte[] get(int index) { * @param index position of element to get * @return Text object for non-null element, null otherwise */ + @Override public Text getObject(int index) { assert index >= 0; if (NULL_CHECKING_ENABLED && isSet(index) == 0) { @@ -182,7 +183,7 @@ public void set(int index, VarCharHolder holder) { BitVectorHelper.setBit(validityBuffer, index); final int dataLength = holder.end - holder.start; final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); lastSet = index; } @@ -203,7 +204,7 @@ public void setSafe(int index, VarCharHolder holder) { BitVectorHelper.setBit(validityBuffer, index); final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); lastSet = index; } @@ -222,10 +223,10 @@ public void set(int index, NullableVarCharHolder holder) { final int startOffset = getStartOffset(index); if (holder.isSet != 0) { final int dataLength = holder.end - holder.start; - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); } else { - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset); } lastSet = index; } @@ -245,7 +246,7 @@ public void setSafe(int index, NullableVarCharHolder holder) { handleSafe(index, dataLength); fillHoles(index); final int startOffset = getStartOffset(index); - offsetBuffer.setInt((index + 1) * OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt((index + 1) * ((long) OFFSET_WIDTH), startOffset + dataLength); valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength); } else { fillEmpties(index + 1); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java b/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java index 8768a90c80b..510bc1169b5 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java @@ -339,6 +339,7 @@ public VectorSchemaRoot slice(int index, int length) { /** * Determine if two VectorSchemaRoots are exactly equal. */ + public boolean equals(VectorSchemaRoot other) { if (other == null) { return false; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java index 898bfe3d397..8e6cdb6c45b 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractContainerVector.java @@ -55,6 +55,7 @@ public void allocateNew() throws OutOfMemoryException { } } + @Override public BufferAllocator getAllocator() { return allocator; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java index 797a5af31f9..1b604eb9082 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; import org.apache.arrow.memory.ArrowBuf; @@ -56,7 +57,7 @@ public abstract class AbstractStructVector extends AbstractContainerVector { } ConflictPolicy conflictPolicy; try { - conflictPolicy = ConflictPolicy.valueOf(conflictPolicyStr.toUpperCase()); + conflictPolicy = ConflictPolicy.valueOf(conflictPolicyStr.toUpperCase(Locale.getDefault())); } catch (Exception e) { conflictPolicy = ConflictPolicy.CONFLICT_REPLACE; } @@ -172,6 +173,7 @@ public void reAlloc() { * @return resultant {@link org.apache.arrow.vector.ValueVector} * @throws java.lang.IllegalStateException raised if there is a hard schema change */ + @Override public T addOrGet(String childName, FieldType fieldType, Class clazz) { final ValueVector existing = getChild(childName); boolean create = false; @@ -411,7 +413,7 @@ public int getBufferSize() { for (final ValueVector v : vectors.values()) { for (final ArrowBuf buf : v.getBuffers(false)) { - actualBufSize += buf.writerIndex(); + actualBufSize += (int) buf.writerIndex(); } } return actualBufSize; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java index 3d8859f87e5..8ba2e48dc2f 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/BaseRepeatedValueVector.java @@ -123,7 +123,7 @@ protected void reallocOffsetBuffer() { } newAllocationSize = CommonUtil.nextPowerOfTwo(newAllocationSize); - newAllocationSize = Math.min(newAllocationSize, (long) (OFFSET_WIDTH) * Integer.MAX_VALUE); + newAllocationSize = Math.min(newAllocationSize, (long) OFFSET_WIDTH * Integer.MAX_VALUE); assert newAllocationSize >= 1; if (newAllocationSize > MAX_ALLOCATION_SIZE || newAllocationSize <= offsetBuffer.capacity()) { @@ -157,7 +157,7 @@ public FieldVector getDataVector() { @Override public void setInitialCapacity(int numRecords) { - offsetAllocationSizeInBytes = (numRecords + 1) * OFFSET_WIDTH; + offsetAllocationSizeInBytes = (numRecords + 1L) * OFFSET_WIDTH; if (vector instanceof BaseFixedWidthVector || vector instanceof BaseVariableWidthVector) { vector.setInitialCapacity(numRecords * RepeatedValueVector.DEFAULT_REPEAT_PER_RECORD); } else { @@ -194,7 +194,7 @@ public void setInitialCapacity(int numRecords, double density) { throw new OversizedAllocationException("Requested amount of memory is more than max allowed"); } - offsetAllocationSizeInBytes = (numRecords + 1) * OFFSET_WIDTH; + offsetAllocationSizeInBytes = (numRecords + 1L) * OFFSET_WIDTH; int innerValueCapacity = Math.max((int) (numRecords * density), 1); @@ -222,7 +222,7 @@ public void setInitialCapacity(int numRecords, double density) { * for in this vector across all records. */ public void setInitialTotalCapacity(int numRecords, int totalNumberOfElements) { - offsetAllocationSizeInBytes = (numRecords + 1) * OFFSET_WIDTH; + offsetAllocationSizeInBytes = (numRecords + 1L) * OFFSET_WIDTH; vector.setInitialCapacity(totalNumberOfElements); } @@ -355,6 +355,7 @@ public int getInnerValueCountAt(int index) { } /** Return if value at index is null (this implementation is always false). */ + @Override public boolean isNull(int index) { return false; } @@ -376,6 +377,7 @@ public int startNewValue(int index) { } /** Preallocates the number of repeated values. */ + @Override public void setValueCount(int valueCount) { this.valueCount = valueCount; while (valueCount > getOffsetBufferValueCapacity()) { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java index 367335436ae..48b53d7de2e 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java @@ -234,11 +234,9 @@ public boolean allocateNewSafe() { } finally { if (!success) { clear(); - return false; } } - - return true; + return success; } private void allocateValidityBuffer(final long size) { @@ -257,12 +255,12 @@ public void reAlloc() { private void reallocValidityBuffer() { final int currentBufferCapacity = checkedCastToInt(validityBuffer.capacity()); - long newAllocationSize = currentBufferCapacity * 2; + long newAllocationSize = currentBufferCapacity * 2L; if (newAllocationSize == 0) { if (validityAllocationSizeInBytes > 0) { newAllocationSize = validityAllocationSizeInBytes; } else { - newAllocationSize = getValidityBufferSizeFromCount(INITIAL_VALUE_ALLOCATION) * 2; + newAllocationSize = getValidityBufferSizeFromCount(INITIAL_VALUE_ALLOCATION) * 2L; } } @@ -273,7 +271,7 @@ private void reallocValidityBuffer() { throw new OversizedAllocationException("Unable to expand the buffer"); } - final ArrowBuf newBuf = allocator.buffer((int) newAllocationSize); + final ArrowBuf newBuf = allocator.buffer(newAllocationSize); newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity); newBuf.setZero(currentBufferCapacity, newBuf.capacity() - currentBufferCapacity); validityBuffer.getReferenceManager().release(1); @@ -468,6 +466,7 @@ public List getObject(int index) { /** * Returns whether the value at index null. */ + @Override public boolean isNull(int index) { return (isSet(index) == 0); } @@ -503,6 +502,7 @@ private int getValidityBufferValueCapacity() { /** * Sets the value at index to null. Reallocates if index is larger than capacity. */ + @Override public void setNull(int index) { while (index >= getValidityBufferValueCapacity()) { reallocValidityBuffer(); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java index 312bed6ab33..b934cbd81db 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java @@ -194,7 +194,7 @@ public void setInitialCapacity(int numRecords, double density) { throw new OversizedAllocationException("Requested amount of memory is more than max allowed"); } - offsetAllocationSizeInBytes = (numRecords + 1) * OFFSET_WIDTH; + offsetAllocationSizeInBytes = (numRecords + 1L) * OFFSET_WIDTH; int innerValueCapacity = Math.max((int) (numRecords * density), 1); @@ -222,7 +222,7 @@ public void setInitialCapacity(int numRecords, double density) { * for in this vector across all records. */ public void setInitialTotalCapacity(int numRecords, int totalNumberOfElements) { - offsetAllocationSizeInBytes = (numRecords + 1) * OFFSET_WIDTH; + offsetAllocationSizeInBytes = (numRecords + 1L) * OFFSET_WIDTH; vector.setInitialCapacity(totalNumberOfElements); } @@ -332,6 +332,7 @@ public void allocateNew() throws OutOfMemoryException { * * @return false if memory allocation fails, true otherwise. */ + @Override public boolean allocateNewSafe() { boolean success = false; try { @@ -347,7 +348,7 @@ public boolean allocateNewSafe() { } catch (Exception e) { e.printStackTrace(); clear(); - return false; + success = false; } finally { if (!dataAlloc) { clear(); @@ -357,10 +358,9 @@ public boolean allocateNewSafe() { } finally { if (!success) { clear(); - return false; } } - return true; + return success; } private void allocateValidityBuffer(final long size) { @@ -408,7 +408,7 @@ protected void reallocOffsetBuffer() { } newAllocationSize = CommonUtil.nextPowerOfTwo(newAllocationSize); - newAllocationSize = Math.min(newAllocationSize, (long) (OFFSET_WIDTH) * Integer.MAX_VALUE); + newAllocationSize = Math.min(newAllocationSize, (long) OFFSET_WIDTH * Integer.MAX_VALUE); assert newAllocationSize >= 1; if (newAllocationSize > MAX_ALLOCATION_SIZE || newAllocationSize <= offsetBuffer.capacity()) { @@ -425,12 +425,12 @@ protected void reallocOffsetBuffer() { private void reallocValidityBuffer() { final int currentBufferCapacity = checkedCastToInt(validityBuffer.capacity()); - long newAllocationSize = currentBufferCapacity * 2; + long newAllocationSize = currentBufferCapacity * 2L; if (newAllocationSize == 0) { if (validityAllocationSizeInBytes > 0) { newAllocationSize = validityAllocationSizeInBytes; } else { - newAllocationSize = getValidityBufferSizeFromCount(INITIAL_VALUE_ALLOCATION) * 2; + newAllocationSize = getValidityBufferSizeFromCount(INITIAL_VALUE_ALLOCATION) * 2L; } } newAllocationSize = CommonUtil.nextPowerOfTwo(newAllocationSize); @@ -440,7 +440,7 @@ private void reallocValidityBuffer() { throw new OversizedAllocationException("Unable to expand the buffer"); } - final ArrowBuf newBuf = allocator.buffer((int) newAllocationSize); + final ArrowBuf newBuf = allocator.buffer(newAllocationSize); newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity); newBuf.setZero(currentBufferCapacity, newBuf.capacity() - currentBufferCapacity); validityBuffer.getReferenceManager().release(1); @@ -526,7 +526,7 @@ public TransferPair makeTransferPair(ValueVector target) { @Override public long getValidityBufferAddress() { - return (validityBuffer.memoryAddress()); + return validityBuffer.memoryAddress(); } @Override @@ -536,7 +536,7 @@ public long getDataBufferAddress() { @Override public long getOffsetBufferAddress() { - return (offsetBuffer.memoryAddress()); + return offsetBuffer.memoryAddress(); } @Override @@ -754,6 +754,7 @@ public UnionLargeListReader getReader() { * Initialize the data vector (and execute callback) if it hasn't already been done, * returns the data vector. */ + @Override public AddOrGetResult addOrGetVector(FieldType fieldType) { boolean created = false; if (vector instanceof NullVector) { @@ -988,6 +989,7 @@ public void setNotNull(int index) { * Sets list at index to be null. * @param index position in vector */ + @Override public void setNull(int index) { while (index >= getValidityAndOffsetValueCapacity()) { reallocValidityAndOffsetBuffers(); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java index cc68d8cb699..5154ac17279 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java @@ -304,10 +304,9 @@ public boolean allocateNewSafe() { } finally { if (!success) { clear(); - return false; } } - return true; + return success; } protected void allocateValidityBuffer(final long size) { @@ -337,12 +336,23 @@ protected void reallocValidityAndOffsetBuffers() { private void reallocValidityBuffer() { final int currentBufferCapacity = checkedCastToInt(validityBuffer.capacity()); - long newAllocationSize = currentBufferCapacity * 2; + long newAllocationSize = getNewAllocationSize(currentBufferCapacity); + + final ArrowBuf newBuf = allocator.buffer(newAllocationSize); + newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity); + newBuf.setZero(currentBufferCapacity, newBuf.capacity() - currentBufferCapacity); + validityBuffer.getReferenceManager().release(1); + validityBuffer = newBuf; + validityAllocationSizeInBytes = (int) newAllocationSize; + } + + private long getNewAllocationSize(int currentBufferCapacity) { + long newAllocationSize = currentBufferCapacity * 2L; if (newAllocationSize == 0) { if (validityAllocationSizeInBytes > 0) { newAllocationSize = validityAllocationSizeInBytes; } else { - newAllocationSize = getValidityBufferSizeFromCount(INITIAL_VALUE_ALLOCATION) * 2; + newAllocationSize = getValidityBufferSizeFromCount(INITIAL_VALUE_ALLOCATION) * 2L; } } newAllocationSize = CommonUtil.nextPowerOfTwo(newAllocationSize); @@ -351,13 +361,7 @@ private void reallocValidityBuffer() { if (newAllocationSize > MAX_ALLOCATION_SIZE) { throw new OversizedAllocationException("Unable to expand the buffer"); } - - final ArrowBuf newBuf = allocator.buffer((int) newAllocationSize); - newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity); - newBuf.setZero(currentBufferCapacity, newBuf.capacity() - currentBufferCapacity); - validityBuffer.getReferenceManager().release(1); - validityBuffer = newBuf; - validityAllocationSizeInBytes = (int) newAllocationSize; + return newAllocationSize; } /** @@ -426,7 +430,7 @@ public TransferPair makeTransferPair(ValueVector target) { @Override public long getValidityBufferAddress() { - return (validityBuffer.memoryAddress()); + return validityBuffer.memoryAddress(); } @Override @@ -436,7 +440,7 @@ public long getDataBufferAddress() { @Override public long getOffsetBufferAddress() { - return (offsetBuffer.memoryAddress()); + return offsetBuffer.memoryAddress(); } @Override @@ -626,6 +630,7 @@ public UnionListReader getReader() { } /** Initialize the child data vector to field type. */ + @Override public AddOrGetResult addOrGetVector(FieldType fieldType) { AddOrGetResult result = super.addOrGetVector(fieldType); invalidateReader(); @@ -838,6 +843,7 @@ public void setNotNull(int index) { * Sets list at index to be null. * @param index position in vector */ + @Override public void setNull(int index) { while (index >= getValidityAndOffsetValueCapacity()) { reallocValidityAndOffsetBuffers(); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java index ed6b7b0bdce..9d0dc5ca3fd 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java @@ -519,7 +519,7 @@ private void reallocValidityBuffer() { final int currentBufferCapacity = checkedCastToInt(validityBuffer.capacity()); long newAllocationSize = getNewAllocationSize(currentBufferCapacity); - final ArrowBuf newBuf = allocator.buffer((int) newAllocationSize); + final ArrowBuf newBuf = allocator.buffer(newAllocationSize); newBuf.setBytes(0, validityBuffer, 0, currentBufferCapacity); newBuf.setZero(currentBufferCapacity, newBuf.capacity() - currentBufferCapacity); validityBuffer.getReferenceManager().release(1); @@ -611,6 +611,7 @@ public void get(int index, ComplexHolder holder) { /** * Return the number of null values in the vector. */ + @Override public int getNullCount() { return BitVectorHelper.getNullCount(validityBuffer, valueCount); } @@ -618,6 +619,7 @@ public int getNullCount() { /** * Returns true if the value at the provided index is null. */ + @Override public boolean isNull(int index) { return isSet(index) == 0; } @@ -647,6 +649,7 @@ public void setIndexDefined(int index) { /** * Marks the value at index as null/not set. */ + @Override public void setNull(int index) { while (index >= getValidityBufferValueCapacity()) { /* realloc the inner buffers if needed */ diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/AbstractBaseReader.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/AbstractBaseReader.java index c80fcb89d0c..028901ee847 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/AbstractBaseReader.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/AbstractBaseReader.java @@ -46,6 +46,7 @@ public int getPosition() { return index; } + @Override public void setPosition(int index) { this.index = index; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java index f7be277f592..bb3bd59a38f 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java @@ -19,6 +19,7 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.util.Locale; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.vector.FieldVector; @@ -301,13 +302,15 @@ public boolean isEmptyStruct() { return writer.isEmptyStruct(); } + @Override protected FieldWriter getWriter() { return writer; } private FieldWriter promoteToUnion() { String name = vector.getField().getName(); - TransferPair tp = vector.getTransferPair(vector.getMinorType().name().toLowerCase(), vector.getAllocator()); + TransferPair tp = vector.getTransferPair(vector.getMinorType().name().toLowerCase(Locale.getDefault()), + vector.getAllocator()); tp.transfer(); if (parentContainer != null) { // TODO allow dictionaries in complex types diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/StructOrListWriterImpl.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/StructOrListWriterImpl.java index 5c4cd2af98d..6a217bbc8b5 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/StructOrListWriterImpl.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/StructOrListWriterImpl.java @@ -88,8 +88,9 @@ public StructOrListWriter struct(final String name) { * * @param name Unused. * - * @deprecated use {@link #listOfStruct()} instead. + * @deprecated use {@link #listOfStruct(String)} instead. */ + @Deprecated public StructOrListWriter listoftstruct(final String name) { return listOfStruct(name); } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionFixedSizeListReader.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionFixedSizeListReader.java index ece729ae563..f69fea3bd57 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionFixedSizeListReader.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionFixedSizeListReader.java @@ -99,6 +99,7 @@ public boolean next() { } } + @Override public void copyAsValue(ListWriter writer) { ComplexCopier.copy(this, (FieldWriter) writer); } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionLargeListReader.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionLargeListReader.java index faf088b5598..0f3ba50f2b3 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionLargeListReader.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionLargeListReader.java @@ -34,7 +34,6 @@ public class UnionLargeListReader extends AbstractFieldReader { private LargeListVector vector; private ValueVector data; - private long index; private static final long OFFSET_WIDTH = 8L; public UnionLargeListReader(LargeListVector vector) { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java index 74548bc985f..7dadcabdcee 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java @@ -60,8 +60,8 @@ public void setPosition(int index) { currentOffset = 0; maxOffset = 0; } else { - currentOffset = vector.getOffsetBuffer().getInt(index * OFFSET_WIDTH) - 1; - maxOffset = vector.getOffsetBuffer().getInt((index + 1) * OFFSET_WIDTH); + currentOffset = vector.getOffsetBuffer().getInt(index * (long) OFFSET_WIDTH) - 1; + maxOffset = vector.getOffsetBuffer().getInt((index + 1) * (long) OFFSET_WIDTH); } } @@ -106,6 +106,7 @@ public boolean next() { } } + @Override public void copyAsValue(ListWriter writer) { ComplexCopier.copy(this, (FieldWriter) writer); } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/dictionary/Dictionary.java b/java/vector/src/main/java/org/apache/arrow/vector/dictionary/Dictionary.java index 6f40e5814b9..5687e4025ac 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/dictionary/Dictionary.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/dictionary/Dictionary.java @@ -60,7 +60,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof Dictionary)) { return false; } Dictionary that = (Dictionary) o; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/table/package-info.java b/java/vector/src/main/java/org/apache/arrow/vector/table/package-info.java index cdd5093b9f5..b11ada51292 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/table/package-info.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/table/package-info.java @@ -17,7 +17,7 @@ package org.apache.arrow.vector.table; -/** +/* * Support for Table, an immutable, columnar, tabular data structure based on FieldVectors. * See the Arrow Java documentation for details: Table */ diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/FloatingPointPrecision.java b/java/vector/src/main/java/org/apache/arrow/vector/types/FloatingPointPrecision.java index c52fc1243d9..85c25322368 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/FloatingPointPrecision.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/FloatingPointPrecision.java @@ -39,7 +39,7 @@ public enum FloatingPointPrecision { } } - private short flatbufID; + private final short flatbufID; private FloatingPointPrecision(short flatbufID) { this.flatbufID = flatbufID; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/FieldType.java b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/FieldType.java index d5c0d85671f..8988993920d 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/FieldType.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/FieldType.java @@ -118,7 +118,7 @@ public boolean equals(Object obj) { return false; } FieldType that = (FieldType) obj; - return Objects.equals(this.isNullable(), that.isNullable()) && + return this.isNullable() == that.isNullable() && Objects.equals(this.getType(), that.getType()) && Objects.equals(this.getDictionary(), that.getDictionary()) && Objects.equals(this.getMetadata(), that.getMetadata()); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java index 9aed357912e..392b3c2e2ec 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java @@ -53,7 +53,6 @@ import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream; -import com.google.errorprone.annotations.InlineMe; import com.google.flatbuffers.FlatBufferBuilder; /** @@ -96,8 +95,6 @@ public static Schema fromJSON(String json) throws IOException { * @return The deserialized schema. */ @Deprecated - @InlineMe(replacement = "Schema.convertSchema(org.apache.arrow.flatbuf.Schema.getRootAsSchema(buffer))", - imports = "org.apache.arrow.vector.types.pojo.Schema") public static Schema deserialize(ByteBuffer buffer) { return convertSchema(org.apache.arrow.flatbuf.Schema.getRootAsSchema(buffer)); } @@ -162,10 +159,10 @@ private Schema(@JsonProperty("fields") Iterable fields, /** * Private constructor to bypass automatic collection copy. - * @param unsafe an ignored argument. Its only purpose is to prevent using the constructor + * @param ignored an ignored argument. Its only purpose is to prevent using the constructor * by accident because of type collisions (List vs Iterable). */ - private Schema(boolean unsafe, List fields, Map metadata) { + private Schema(boolean ignored, List fields, Map metadata) { this.fields = fields; this.metadata = metadata; } @@ -253,8 +250,7 @@ public int getSchema(FlatBufferBuilder builder) { public byte[] serializeAsMessage() { ByteArrayOutputStream out = new ByteArrayOutputStream(); try (WriteChannel channel = new WriteChannel(Channels.newChannel(out))) { - long size = MessageSerializer.serialize( - new WriteChannel(Channels.newChannel(out)), this); + MessageSerializer.serialize(channel, this); return out.toByteArray(); } catch (IOException ex) { throw new RuntimeException(ex); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java b/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java index 7c9c0e94088..1f18587afdf 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java @@ -27,8 +27,6 @@ import java.util.stream.Collectors; import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * An implementation of map that supports constant time look-up by a generic key or an ordinal. @@ -48,7 +46,6 @@ * @param value type */ public class MapWithOrdinalImpl implements MapWithOrdinal { - private static final Logger logger = LoggerFactory.getLogger(MapWithOrdinalImpl.class); private final Map> primary = new LinkedHashMap<>(); private final IntObjectHashMap secondary = new IntObjectHashMap<>(); @@ -93,10 +90,6 @@ public V put(K key, V value) { return oldPair == null ? null : oldPair.getValue(); } - public boolean put(K key, V value, boolean override) { - return put(key, value) != null; - } - @Override public V remove(Object key) { final Entry oldPair = primary.remove(key); @@ -146,6 +139,7 @@ public Set> entrySet() { * @param id ordinal value for lookup * @return an instance of V */ + @Override public V getByOrdinal(int id) { return secondary.get(id); } @@ -156,6 +150,7 @@ public V getByOrdinal(int id) { * @param key key for ordinal lookup * @return ordinal value corresponding to key if it exists or -1 */ + @Override public int getOrdinal(K key) { Map.Entry pair = primary.get(key); if (pair != null) { From b664f6db7af8918a7faa69c1a99ea29ebf32b2bc Mon Sep 17 00:00:00 2001 From: vibhatha Date: Thu, 11 Jan 2024 22:43:49 +0530 Subject: [PATCH 15/23] fixing warnings v15: vector s3 (removing mistakenly added maven-compiler plugin) --- java/vector/pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/java/vector/pom.xml b/java/vector/pom.xml index 828ccec1a02..dc453963b62 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -212,14 +212,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 9 - 9 - - From dfaa06336021921a91beacfcdd8ab6333fe2a5cd Mon Sep 17 00:00:00 2001 From: vibhatha Date: Fri, 12 Jan 2024 18:14:47 +0530 Subject: [PATCH 16/23] fixing warnings v16: vector s4 --- .../arrow/vector/TestBitVectorHelper.java | 6 +- .../org/apache/arrow/vector/TestCopyFrom.java | 10 +- .../arrow/vector/TestDictionaryVector.java | 35 ++--- .../arrow/vector/TestFixedSizeListVector.java | 71 +++++----- .../vector/TestLargeVarBinaryVector.java | 20 +-- .../arrow/vector/TestLargeVarCharVector.java | 49 +++---- .../apache/arrow/vector/TestListVector.java | 130 +++++++++--------- .../vector/compare/TestTypeEqualsVisitor.java | 6 - .../complex/impl/TestPromotableWriter.java | 90 ++++++------ .../arrow/vector/ipc/TestArrowStream.java | 4 +- .../ipc/TestUIntDictionaryRoundTrip.java | 3 +- .../message/TestMessageMetadataResult.java | 2 +- .../arrow/vector/table/BaseTableTest.java | 14 +- .../apache/arrow/vector/table/TestUtils.java | 21 +-- .../testing/TestValueVectorPopulator.java | 18 ++- .../vector/util/TestReusableByteArray.java | 46 ++++--- 16 files changed, 275 insertions(+), 250 deletions(-) diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java index 96005dc511c..1da4a4c4914 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java @@ -47,7 +47,7 @@ public void testGetNullCount() throws Exception { validityBuffer.setByte(0, 0xFF); count = BitVectorHelper.getNullCount(validityBuffer, 8); - assertEquals(count, 0); + assertEquals(0, count); validityBuffer.close(); // test case 3, 1 null value for 0x7F @@ -55,7 +55,7 @@ public void testGetNullCount() throws Exception { validityBuffer.setByte(0, 0x7F); count = BitVectorHelper.getNullCount(validityBuffer, 8); - assertEquals(count, 1); + assertEquals(1, count); validityBuffer.close(); // test case 4, validity buffer has multiple bytes, 11 items @@ -64,7 +64,7 @@ public void testGetNullCount() throws Exception { validityBuffer.setByte(1, 0b01010101); count = BitVectorHelper.getNullCount(validityBuffer, 11); - assertEquals(count, 5); + assertEquals(5, count); validityBuffer.close(); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java index 3786f63c31b..873e3e47df9 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertNull; import java.math.BigDecimal; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Period; @@ -84,7 +84,7 @@ public void testCopyFromWithNulls() { if (i % 3 == 0) { continue; } - byte[] b = Integer.toString(i).getBytes(); + byte[] b = Integer.toString(i).getBytes(StandardCharsets.UTF_8); vector.setSafe(i, b, 0, b.length); } @@ -156,7 +156,7 @@ public void testCopyFromWithNulls1() { if (i % 3 == 0) { continue; } - byte[] b = Integer.toString(i).getBytes(); + byte[] b = Integer.toString(i).getBytes(StandardCharsets.UTF_8); vector.setSafe(i, b, 0, b.length); } @@ -950,7 +950,7 @@ public void testCopyFromWithNulls13() { assertEquals(0, vector1.getValueCount()); int initialCapacity = vector1.getValueCapacity(); - final double baseValue = 104567897654.876543654; + final double baseValue = 104567897654.87654; final BigDecimal[] decimals = new BigDecimal[4096]; for (int i = 0; i < initialCapacity; i++) { if ((i & 1) == 0) { @@ -1082,7 +1082,7 @@ public void testCopySafeArrow7837() { // to trigger a reallocation of the vector. vc2.setInitialCapacity(/*valueCount*/20, /*density*/0.5); - vc1.setSafe(0, "1234567890".getBytes(Charset.forName("utf-8"))); + vc1.setSafe(0, "1234567890".getBytes(StandardCharsets.UTF_8)); assertFalse(vc1.isNull(0)); assertEquals(vc1.getObject(0).toString(), "1234567890"); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java index 501059733c6..17758f6b414 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java @@ -841,7 +841,8 @@ public void testEncodeStructSubFieldWithCertainColumns() { // initialize dictionaries DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); - setVector(dictVector1, "aa".getBytes(), "bb".getBytes(), "cc".getBytes(), "dd".getBytes()); + setVector(dictVector1, "aa".getBytes(StandardCharsets.UTF_8), "bb".getBytes(StandardCharsets.UTF_8), + "cc".getBytes(StandardCharsets.UTF_8), "dd".getBytes(StandardCharsets.UTF_8)); provider.put(new Dictionary(dictVector1, new DictionaryEncoding(1L, false, null))); StructSubfieldEncoder encoder = new StructSubfieldEncoder(allocator, provider); @@ -1049,20 +1050,20 @@ private void testDictionary(Dictionary dictionary, ToIntBiFunction ((UInt2Vector) vector).get(index)); } } @@ -1096,7 +1097,7 @@ public void testDictionaryUInt4() { setVector(dictionaryVector, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); Dictionary dictionary4 = new Dictionary(dictionaryVector, new DictionaryEncoding(/*id=*/30L, /*ordered=*/false, - /*indexType=*/new ArrowType.Int(/*indexType=*/32, /*isSigned*/false))); + /*indexType=*/new ArrowType.Int(/*bitWidth=*/32, /*isSigned*/false))); testDictionary(dictionary4, (vector, index) -> ((UInt4Vector) vector).get(index)); } } @@ -1107,7 +1108,7 @@ public void testDictionaryUInt8() { setVector(dictionaryVector, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); Dictionary dictionary8 = new Dictionary(dictionaryVector, new DictionaryEncoding(/*id=*/40L, /*ordered=*/false, - /*indexType=*/new ArrowType.Int(/*indexType=*/64, /*isSigned*/false))); + /*indexType=*/new ArrowType.Int(/*bitWidth=*/64, /*isSigned*/false))); testDictionary(dictionary8, (vector, index) -> (int) ((UInt8Vector) vector).get(index)); } } @@ -1119,13 +1120,13 @@ public void testDictionaryUIntOverflow() { try (VarCharVector dictionaryVector = new VarCharVector("dict vector", allocator)) { dictionaryVector.allocateNew(vecLength * 3, vecLength); for (int i = 0; i < vecLength; i++) { - dictionaryVector.set(i, String.valueOf(i).getBytes()); + dictionaryVector.set(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionaryVector.setValueCount(vecLength); Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(/*id=*/10L, /*ordered=*/false, - /*indexType=*/new ArrowType.Int(/*indexType=*/8, /*isSigned*/false))); + /*indexType=*/new ArrowType.Int(/*bitWidth=*/8, /*isSigned*/false))); try (VarCharVector vector = new VarCharVector("vector", allocator)) { setVector(vector, "255"); @@ -1137,7 +1138,7 @@ public void testDictionaryUIntOverflow() { try (VarCharVector decodedVector = (VarCharVector) DictionaryEncoder.decode(encodedVector, dictionary)) { assertEquals(1, decodedVector.getValueCount()); - assertArrayEquals("255".getBytes(), decodedVector.get(0)); + assertArrayEquals("255".getBytes(StandardCharsets.UTF_8), decodedVector.get(0)); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java index 0023b1dddb8..bde6dd491dd 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java @@ -25,6 +25,7 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -61,7 +62,7 @@ public void terminate() throws Exception { @Test public void testIntType() { - try (FixedSizeListVector vector = FixedSizeListVector.empty("list", 2, allocator)) { + try (FixedSizeListVector vector = FixedSizeListVector.empty("list", /*size=*/2, allocator)) { IntVector nested = (IntVector) vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())).getVector(); vector.allocateNew(); @@ -88,7 +89,7 @@ public void testIntType() { @Test public void testFloatTypeNullable() { - try (FixedSizeListVector vector = FixedSizeListVector.empty("list", 2, allocator)) { + try (FixedSizeListVector vector = FixedSizeListVector.empty("list", /*size=*/2, allocator)) { Float4Vector nested = (Float4Vector) vector.addOrGetVector(FieldType.nullable(MinorType.FLOAT4.getType())) .getVector(); vector.allocateNew(); @@ -235,7 +236,7 @@ public void testTransferPair() { @Test public void testConsistentChildName() throws Exception { - try (FixedSizeListVector listVector = FixedSizeListVector.empty("sourceVector", 2, allocator)) { + try (FixedSizeListVector listVector = FixedSizeListVector.empty("sourceVector", /*size=*/2, allocator)) { String emptyListStr = listVector.getField().toString(); Assert.assertTrue(emptyListStr.contains(ListVector.DATA_VECTOR_NAME)); @@ -251,7 +252,7 @@ public void testUnionFixedSizeListWriterWithNulls() throws Exception { * each list of size 3 and having its data values alternating between null and a non-null. * Read and verify */ - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/3, allocator)) { + try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*size=*/3, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -279,7 +280,7 @@ public void testUnionFixedSizeListWriterWithNulls() throws Exception { @Test public void testUnionFixedSizeListWriter() throws Exception { - try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", 3, allocator)) { + try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", /*size=*/3, allocator)) { UnionFixedSizeListWriter writer1 = vector1.getWriter(); writer1.allocate(); @@ -307,7 +308,7 @@ public void testUnionFixedSizeListWriter() throws Exception { @Test public void testWriteDecimal() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/3, allocator)) { + try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*size=*/3, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -335,7 +336,7 @@ public void testWriteDecimal() throws Exception { @Test public void testDecimalIndexCheck() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/3, allocator)) { + try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*size=*/3, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -355,7 +356,7 @@ public void testDecimalIndexCheck() throws Exception { @Test(expected = IllegalStateException.class) public void testWriteIllegalData() throws Exception { - try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", 3, allocator)) { + try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", /*size=*/3, allocator)) { UnionFixedSizeListWriter writer1 = vector1.getWriter(); writer1.allocate(); @@ -378,7 +379,7 @@ public void testWriteIllegalData() throws Exception { @Test public void testSplitAndTransfer() throws Exception { - try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", 3, allocator)) { + try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", /*size=*/3, allocator)) { UnionFixedSizeListWriter writer1 = vector1.getWriter(); writer1.allocate(); @@ -399,9 +400,9 @@ public void testSplitAndTransfer() throws Exception { assertEquals(2, targetVector.getValueCount()); int[] realValue1 = convertListToIntArray(targetVector.getObject(0)); - assertTrue(Arrays.equals(values1, realValue1)); + assertArrayEquals(values1, realValue1); int[] realValue2 = convertListToIntArray(targetVector.getObject(1)); - assertTrue(Arrays.equals(values2, realValue2)); + assertArrayEquals(values2, realValue2); targetVector.clear(); } @@ -409,7 +410,7 @@ public void testSplitAndTransfer() throws Exception { @Test public void testZeroWidthVector() { - try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", 0, allocator)) { + try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", /*size=*/0, allocator)) { UnionFixedSizeListWriter writer1 = vector1.getWriter(); writer1.allocate(); @@ -440,7 +441,7 @@ public void testZeroWidthVector() { @Test public void testVectorWithNulls() { - try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", 4, allocator)) { + try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", /*size=*/4, allocator)) { UnionFixedSizeListWriter writer1 = vector1.getWriter(); writer1.allocate(); @@ -472,7 +473,7 @@ public void testVectorWithNulls() { @Test public void testWriteVarCharHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*size=*/4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -491,7 +492,7 @@ public void testWriteVarCharHelpers() throws Exception { @Test public void testWriteLargeVarCharHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*size=*/4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -510,43 +511,47 @@ public void testWriteLargeVarCharHelpers() throws Exception { @Test public void testWriteVarBinaryHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*size=*/4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); writer.startList(); - writer.writeVarBinary("row1,1".getBytes()); - writer.writeVarBinary("row1,2".getBytes(), 0, "row1,2".getBytes().length); - writer.writeVarBinary(ByteBuffer.wrap("row1,3".getBytes())); - writer.writeVarBinary(ByteBuffer.wrap("row1,4".getBytes()), 0, "row1,4".getBytes().length); + writer.writeVarBinary("row1,1".getBytes(StandardCharsets.UTF_8)); + writer.writeVarBinary("row1,2".getBytes(StandardCharsets.UTF_8), 0, + "row1,2".getBytes(StandardCharsets.UTF_8).length); + writer.writeVarBinary(ByteBuffer.wrap("row1,3".getBytes(StandardCharsets.UTF_8))); + writer.writeVarBinary(ByteBuffer.wrap("row1,4".getBytes(StandardCharsets.UTF_8)), 0, + "row1,4".getBytes(StandardCharsets.UTF_8).length); writer.endList(); - assertEquals("row1,1", new String((byte[]) (vector.getObject(0).get(0)))); - assertEquals("row1,2", new String((byte[]) (vector.getObject(0).get(1)))); - assertEquals("row1,3", new String((byte[]) (vector.getObject(0).get(2)))); - assertEquals("row1,4", new String((byte[]) (vector.getObject(0).get(3)))); + assertEquals("row1,1", new String((byte[]) vector.getObject(0).get(0), StandardCharsets.UTF_8)); + assertEquals("row1,2", new String((byte[]) vector.getObject(0).get(1), StandardCharsets.UTF_8)); + assertEquals("row1,3", new String((byte[]) vector.getObject(0).get(2), StandardCharsets.UTF_8)); + assertEquals("row1,4", new String((byte[]) vector.getObject(0).get(3), StandardCharsets.UTF_8)); } } @Test public void testWriteLargeVarBinaryHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*size=*/4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); writer.startList(); - writer.writeLargeVarBinary("row1,1".getBytes()); - writer.writeLargeVarBinary("row1,2".getBytes(), 0, "row1,2".getBytes().length); - writer.writeLargeVarBinary(ByteBuffer.wrap("row1,3".getBytes())); - writer.writeLargeVarBinary(ByteBuffer.wrap("row1,4".getBytes()), 0, "row1,4".getBytes().length); + writer.writeLargeVarBinary("row1,1".getBytes(StandardCharsets.UTF_8)); + writer.writeLargeVarBinary("row1,2".getBytes(StandardCharsets.UTF_8), 0, + "row1,2".getBytes(StandardCharsets.UTF_8).length); + writer.writeLargeVarBinary(ByteBuffer.wrap("row1,3".getBytes(StandardCharsets.UTF_8))); + writer.writeLargeVarBinary(ByteBuffer.wrap("row1,4".getBytes(StandardCharsets.UTF_8)), 0, + "row1,4".getBytes(StandardCharsets.UTF_8).length); writer.endList(); - assertEquals("row1,1", new String((byte[]) (vector.getObject(0).get(0)))); - assertEquals("row1,2", new String((byte[]) (vector.getObject(0).get(1)))); - assertEquals("row1,3", new String((byte[]) (vector.getObject(0).get(2)))); - assertEquals("row1,4", new String((byte[]) (vector.getObject(0).get(3)))); + assertEquals("row1,1", new String((byte[]) vector.getObject(0).get(0), StandardCharsets.UTF_8)); + assertEquals("row1,2", new String((byte[]) vector.getObject(0).get(1), StandardCharsets.UTF_8)); + assertEquals("row1,3", new String((byte[]) vector.getObject(0).get(2), StandardCharsets.UTF_8)); + assertEquals("row1,4", new String((byte[]) vector.getObject(0).get(3), StandardCharsets.UTF_8)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java index ecababde8de..36607903b01 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java @@ -22,7 +22,9 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.Objects; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; @@ -61,7 +63,7 @@ public void testSetNullableLargeVarBinaryHolder() { String str = "hello"; try (ArrowBuf buf = allocator.buffer(16)) { - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); binHolder.start = 0; binHolder.end = str.length(); @@ -72,7 +74,7 @@ public void testSetNullableLargeVarBinaryHolder() { // verify results assertTrue(vector.isNull(0)); - assertEquals(str, new String(vector.get(1))); + assertEquals(str, new String(Objects.requireNonNull(vector.get(1)), StandardCharsets.UTF_8)); } } } @@ -90,7 +92,7 @@ public void testSetNullableLargeVarBinaryHolderSafe() { String str = "hello world"; try (ArrowBuf buf = allocator.buffer(16)) { - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); binHolder.start = 0; binHolder.end = str.length(); @@ -100,7 +102,7 @@ public void testSetNullableLargeVarBinaryHolderSafe() { vector.setSafe(1, nullHolder); // verify results - assertEquals(str, new String(vector.get(0))); + assertEquals(str, new String(Objects.requireNonNull(vector.get(0)), StandardCharsets.UTF_8)); assertTrue(vector.isNull(1)); } } @@ -113,18 +115,18 @@ public void testGetBytesRepeatedly() { final String str = "hello world"; final String str2 = "foo"; - vector.setSafe(0, str.getBytes()); - vector.setSafe(1, str2.getBytes()); + vector.setSafe(0, str.getBytes(StandardCharsets.UTF_8)); + vector.setSafe(1, str2.getBytes(StandardCharsets.UTF_8)); // verify results ReusableByteArray reusableByteArray = new ReusableByteArray(); vector.read(0, reusableByteArray); byte[] oldBuffer = reusableByteArray.getBuffer(); - assertArrayEquals(str.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), + assertArrayEquals(str.getBytes(StandardCharsets.UTF_8), Arrays.copyOfRange(reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); vector.read(1, reusableByteArray); - assertArrayEquals(str2.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), + assertArrayEquals(str2.getBytes(StandardCharsets.UTF_8), Arrays.copyOfRange(reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); // There should not have been any reallocation since the newer value is smaller in length. @@ -137,7 +139,7 @@ public void testGetTransferPairWithField() { try (BufferAllocator childAllocator1 = allocator.newChildAllocator("child1", 1000000, 1000000); LargeVarBinaryVector v1 = new LargeVarBinaryVector("v1", childAllocator1)) { v1.allocateNew(); - v1.setSafe(4094, "hello world".getBytes(), 0, 11); + v1.setSafe(4094, "hello world".getBytes(StandardCharsets.UTF_8), 0, 11); v1.setValueCount(4001); TransferPair tp = v1.getTransferPair(v1.getField(), allocator); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java index 7d074c39364..62d09da86d6 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java @@ -27,6 +27,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; @@ -48,12 +49,12 @@ public class TestLargeVarCharVector { - private static final byte[] STR1 = "AAAAA1".getBytes(); - private static final byte[] STR2 = "BBBBBBBBB2".getBytes(); - private static final byte[] STR3 = "CCCC3".getBytes(); - private static final byte[] STR4 = "DDDDDDDD4".getBytes(); - private static final byte[] STR5 = "EEE5".getBytes(); - private static final byte[] STR6 = "FFFFF6".getBytes(); + private static final byte[] STR1 = "AAAAA1".getBytes(StandardCharsets.UTF_8); + private static final byte[] STR2 = "BBBBBBBBB2".getBytes(StandardCharsets.UTF_8); + private static final byte[] STR3 = "CCCC3".getBytes(StandardCharsets.UTF_8); + private static final byte[] STR4 = "DDDDDDDD4".getBytes(StandardCharsets.UTF_8); + private static final byte[] STR5 = "EEE5".getBytes(StandardCharsets.UTF_8); + private static final byte[] STR6 = "FFFFF6".getBytes(StandardCharsets.UTF_8); private BufferAllocator allocator; @@ -74,7 +75,7 @@ public void testTransfer() { LargeVarCharVector v1 = new LargeVarCharVector("v1", childAllocator1); LargeVarCharVector v2 = new LargeVarCharVector("v2", childAllocator2);) { v1.allocateNew(); - v1.setSafe(4094, "hello world".getBytes(), 0, 11); + v1.setSafe(4094, "hello world".getBytes(StandardCharsets.UTF_8), 0, 11); v1.setValueCount(4001); long memoryBeforeTransfer = childAllocator1.getAllocatedMemory(); @@ -207,12 +208,12 @@ public void testSizeOfValueBuffer() { @Test public void testSetLastSetUsage() { - final byte[] STR1 = "AAAAA1".getBytes(); - final byte[] STR2 = "BBBBBBBBB2".getBytes(); - final byte[] STR3 = "CCCC3".getBytes(); - final byte[] STR4 = "DDDDDDDD4".getBytes(); - final byte[] STR5 = "EEE5".getBytes(); - final byte[] STR6 = "FFFFF6".getBytes(); + final byte[] STR1 = "AAAAA1".getBytes(StandardCharsets.UTF_8); + final byte[] STR2 = "BBBBBBBBB2".getBytes(StandardCharsets.UTF_8); + final byte[] STR3 = "CCCC3".getBytes(StandardCharsets.UTF_8); + final byte[] STR4 = "DDDDDDDD4".getBytes(StandardCharsets.UTF_8); + final byte[] STR5 = "EEE5".getBytes(StandardCharsets.UTF_8); + final byte[] STR6 = "FFFFF6".getBytes(StandardCharsets.UTF_8); try (final LargeVarCharVector vector = new LargeVarCharVector("myvector", allocator)) { vector.allocateNew(1024 * 10, 1024); @@ -353,7 +354,7 @@ public void testSplitAndTransfer() { for (int i = 0; i < length; i++) { final boolean expectedSet = ((start + i) % 3) == 0; if (expectedSet) { - final byte[] expectedValue = compareArray[start + i].getBytes(); + final byte[] expectedValue = compareArray[start + i].getBytes(StandardCharsets.UTF_8); assertFalse(newLargeVarCharVector.isNull(i)); assertArrayEquals(expectedValue, newLargeVarCharVector.get(i)); } else { @@ -367,8 +368,8 @@ public void testSplitAndTransfer() { @Test public void testReallocAfterVectorTransfer() { - final byte[] STR1 = "AAAAA1".getBytes(); - final byte[] STR2 = "BBBBBBBBB2".getBytes(); + final byte[] STR1 = "AAAAA1".getBytes(StandardCharsets.UTF_8); + final byte[] STR2 = "BBBBBBBBB2".getBytes(StandardCharsets.UTF_8); try (final LargeVarCharVector vector = new LargeVarCharVector("vector", allocator)) { /* 4096 values with 10 byte per record */ @@ -675,7 +676,7 @@ public void testSetNullableLargeVarCharHolder() { String str = "hello"; ArrowBuf buf = allocator.buffer(16); - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); stringHolder.start = 0; stringHolder.end = str.length(); @@ -686,7 +687,7 @@ public void testSetNullableLargeVarCharHolder() { // verify results assertTrue(vector.isNull(0)); - assertEquals(str, new String(vector.get(1))); + assertEquals(str, new String(Objects.requireNonNull(vector.get(1)), StandardCharsets.UTF_8)); buf.close(); } @@ -705,7 +706,7 @@ public void testSetNullableLargeVarCharHolderSafe() { String str = "hello world"; ArrowBuf buf = allocator.buffer(16); - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); stringHolder.start = 0; stringHolder.end = str.length(); @@ -715,7 +716,7 @@ public void testSetNullableLargeVarCharHolderSafe() { vector.setSafe(1, nullHolder); // verify results - assertEquals(str, new String(vector.get(0))); + assertEquals(str, new String(Objects.requireNonNull(vector.get(0)), StandardCharsets.UTF_8)); assertTrue(vector.isNull(1)); buf.close(); @@ -743,7 +744,7 @@ public void testLargeVariableWidthVectorNullHashCode() { largeVarChVec.allocateNew(100, 1); largeVarChVec.setValueCount(1); - largeVarChVec.set(0, "abc".getBytes()); + largeVarChVec.set(0, "abc".getBytes(StandardCharsets.UTF_8)); largeVarChVec.setNull(0); assertEquals(0, largeVarChVec.hashCode(0)); @@ -756,7 +757,7 @@ public void testUnloadLargeVariableWidthVector() { largeVarCharVector.allocateNew(5, 2); largeVarCharVector.setValueCount(2); - largeVarCharVector.set(0, "abcd".getBytes()); + largeVarCharVector.set(0, "abcd".getBytes(StandardCharsets.UTF_8)); List bufs = largeVarCharVector.getFieldBuffers(); assertEquals(3, bufs.size()); @@ -821,7 +822,7 @@ public void testGetTransferPairWithField() { try (BufferAllocator childAllocator1 = allocator.newChildAllocator("child1", 1000000, 1000000); LargeVarCharVector v1 = new LargeVarCharVector("v1", childAllocator1)) { v1.allocateNew(); - v1.setSafe(4094, "hello world".getBytes(), 0, 11); + v1.setSafe(4094, "hello world".getBytes(StandardCharsets.UTF_8), 0, 11); v1.setValueCount(4001); TransferPair tp = v1.getTransferPair(v1.getField(), allocator); @@ -835,7 +836,7 @@ public void testGetTransferPairWithField() { private void populateLargeVarcharVector(final LargeVarCharVector vector, int valueCount, String[] values) { for (int i = 0; i < valueCount; i += 3) { final String s = String.format("%010d", i); - vector.set(i, s.getBytes()); + vector.set(i, s.getBytes(StandardCharsets.UTF_8)); if (values != null) { values[i] = s; } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java index 278f497b479..97f2d9fd6de 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java @@ -107,9 +107,9 @@ public void testCopyFrom() throws Exception { Object result = outVector.getObject(0); ArrayList resultSet = (ArrayList) result; assertEquals(3, resultSet.size()); - assertEquals(new Long(1), (Long) resultSet.get(0)); - assertEquals(new Long(2), (Long) resultSet.get(1)); - assertEquals(new Long(3), (Long) resultSet.get(2)); + assertEquals(Long.valueOf(1), resultSet.get(0)); + assertEquals(Long.valueOf(2), resultSet.get(1)); + assertEquals(Long.valueOf(3), resultSet.get(2)); /* index 1 */ result = outVector.getObject(1); @@ -148,7 +148,7 @@ public void testSetLastSetUsage() throws Exception { assertEquals(Integer.toString(-1), Integer.toString(listVector.getLastSet())); int index = 0; - int offset = 0; + int offset; /* write [10, 11, 12] to the list vector at index 0 */ BitVectorHelper.setBit(validityBuffer, index); @@ -227,36 +227,36 @@ public void testSetLastSetUsage() throws Exception { assertEquals(Integer.toString(0), Integer.toString(offset)); Long actual = dataVector.getObject(offset); - assertEquals(new Long(10), actual); + assertEquals(Long.valueOf(10), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(11), actual); + assertEquals(Long.valueOf(11), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(12), actual); + assertEquals(Long.valueOf(12), actual); index++; offset = offsetBuffer.getInt(index * ListVector.OFFSET_WIDTH); assertEquals(Integer.toString(3), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(13), actual); + assertEquals(Long.valueOf(13), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(14), actual); + assertEquals(Long.valueOf(14), actual); index++; offset = offsetBuffer.getInt(index * ListVector.OFFSET_WIDTH); assertEquals(Integer.toString(5), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(15), actual); + assertEquals(Long.valueOf(15), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(16), actual); + assertEquals(Long.valueOf(16), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(17), actual); + assertEquals(Long.valueOf(17), actual); index++; offset = offsetBuffer.getInt(index * ListVector.OFFSET_WIDTH); @@ -328,8 +328,8 @@ public void testSplitAndTransfer() throws Exception { /* check the vector output */ int index = 0; - int offset = 0; - Long actual = null; + int offset; + Long actual; /* index 0 */ assertFalse(listVector.isNull(index)); @@ -337,13 +337,13 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(0), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(10), actual); + assertEquals(Long.valueOf(10), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(11), actual); + assertEquals(Long.valueOf(11), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(12), actual); + assertEquals(Long.valueOf(12), actual); /* index 1 */ index++; @@ -352,10 +352,10 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(3), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(13), actual); + assertEquals(Long.valueOf(13), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(14), actual); + assertEquals(Long.valueOf(14), actual); /* index 2 */ index++; @@ -364,16 +364,16 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(5), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(15), actual); + assertEquals(Long.valueOf(15), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(16), actual); + assertEquals(Long.valueOf(16), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(17), actual); + assertEquals(Long.valueOf(17), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(18), actual); + assertEquals(Long.valueOf(18), actual); /* index 3 */ index++; @@ -382,7 +382,7 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(9), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(19), actual); + assertEquals(Long.valueOf(19), actual); /* index 4 */ index++; @@ -391,16 +391,16 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(10), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(20), actual); + assertEquals(Long.valueOf(20), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(21), actual); + assertEquals(Long.valueOf(21), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(22), actual); + assertEquals(Long.valueOf(22), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(23), actual); + assertEquals(Long.valueOf(23), actual); /* index 5 */ index++; @@ -527,15 +527,15 @@ public void testNestedListVector() throws Exception { assertEquals(4, resultSet.get(1).size()); /* size of second inner list */ list = resultSet.get(0); - assertEquals(new Long(50), list.get(0)); - assertEquals(new Long(100), list.get(1)); - assertEquals(new Long(200), list.get(2)); + assertEquals(Long.valueOf(50), list.get(0)); + assertEquals(Long.valueOf(100), list.get(1)); + assertEquals(Long.valueOf(200), list.get(2)); list = resultSet.get(1); - assertEquals(new Long(75), list.get(0)); - assertEquals(new Long(125), list.get(1)); - assertEquals(new Long(150), list.get(2)); - assertEquals(new Long(175), list.get(3)); + assertEquals(Long.valueOf(75), list.get(0)); + assertEquals(Long.valueOf(125), list.get(1)); + assertEquals(Long.valueOf(150), list.get(2)); + assertEquals(Long.valueOf(175), list.get(3)); /* get listVector value at index 1 -- the value itself is a listvector */ result = listVector.getObject(1); @@ -547,16 +547,16 @@ public void testNestedListVector() throws Exception { assertEquals(3, resultSet.get(2).size()); /* size of third inner list */ list = resultSet.get(0); - assertEquals(new Long(10), list.get(0)); + assertEquals(Long.valueOf(10), list.get(0)); list = resultSet.get(1); - assertEquals(new Long(15), list.get(0)); - assertEquals(new Long(20), list.get(1)); + assertEquals(Long.valueOf(15), list.get(0)); + assertEquals(Long.valueOf(20), list.get(1)); list = resultSet.get(2); - assertEquals(new Long(25), list.get(0)); - assertEquals(new Long(30), list.get(1)); - assertEquals(new Long(35), list.get(2)); + assertEquals(Long.valueOf(25), list.get(0)); + assertEquals(Long.valueOf(30), list.get(1)); + assertEquals(Long.valueOf(35), list.get(2)); /* check underlying bitVector */ assertFalse(listVector.isNull(0)); @@ -661,13 +661,13 @@ public void testNestedListVector2() throws Exception { assertEquals(2, resultSet.get(1).size()); /* size of second inner list */ list = resultSet.get(0); - assertEquals(new Long(50), list.get(0)); - assertEquals(new Long(100), list.get(1)); - assertEquals(new Long(200), list.get(2)); + assertEquals(Long.valueOf(50), list.get(0)); + assertEquals(Long.valueOf(100), list.get(1)); + assertEquals(Long.valueOf(200), list.get(2)); list = resultSet.get(1); - assertEquals(new Long(75), list.get(0)); - assertEquals(new Long(125), list.get(1)); + assertEquals(Long.valueOf(75), list.get(0)); + assertEquals(Long.valueOf(125), list.get(1)); /* get listVector value at index 1 -- the value itself is a listvector */ result = listVector.getObject(1); @@ -678,13 +678,13 @@ public void testNestedListVector2() throws Exception { assertEquals(3, resultSet.get(1).size()); /* size of second inner list */ list = resultSet.get(0); - assertEquals(new Long(15), list.get(0)); - assertEquals(new Long(20), list.get(1)); + assertEquals(Long.valueOf(15), list.get(0)); + assertEquals(Long.valueOf(20), list.get(1)); list = resultSet.get(1); - assertEquals(new Long(25), list.get(0)); - assertEquals(new Long(30), list.get(1)); - assertEquals(new Long(35), list.get(2)); + assertEquals(Long.valueOf(25), list.get(0)); + assertEquals(Long.valueOf(30), list.get(1)); + assertEquals(Long.valueOf(35), list.get(2)); /* check underlying bitVector */ assertFalse(listVector.isNull(0)); @@ -728,15 +728,15 @@ public void testGetBufferAddress() throws Exception { Object result = listVector.getObject(0); ArrayList resultSet = (ArrayList) result; assertEquals(3, resultSet.size()); - assertEquals(new Long(50), resultSet.get(0)); - assertEquals(new Long(100), resultSet.get(1)); - assertEquals(new Long(200), resultSet.get(2)); + assertEquals(Long.valueOf(50), resultSet.get(0)); + assertEquals(Long.valueOf(100), resultSet.get(1)); + assertEquals(Long.valueOf(200), resultSet.get(2)); result = listVector.getObject(1); resultSet = (ArrayList) result; assertEquals(2, resultSet.size()); - assertEquals(new Long(250), resultSet.get(0)); - assertEquals(new Long(300), resultSet.get(1)); + assertEquals(Long.valueOf(250), resultSet.get(0)); + assertEquals(Long.valueOf(300), resultSet.get(1)); List buffers = listVector.getFieldBuffers(); @@ -744,7 +744,7 @@ public void testGetBufferAddress() throws Exception { long offsetAddress = listVector.getOffsetBufferAddress(); try { - long dataAddress = listVector.getDataBufferAddress(); + listVector.getDataBufferAddress(); } catch (UnsupportedOperationException ue) { error = true; } finally { @@ -777,7 +777,7 @@ public void testSetInitialCapacity() { try (final ListVector vector = ListVector.empty("", allocator)) { vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); - /** + /* * use the default multiplier of 5, * 512 * 5 => 2560 * 4 => 10240 bytes => 16KB => 4096 value capacity. */ @@ -792,7 +792,7 @@ public void testSetInitialCapacity() { assertEquals(512, vector.getValueCapacity()); assertTrue(vector.getDataVector().getValueCapacity() >= 512 * 4); - /** + /* * inner value capacity we pass to data vector is 512 * 0.1 => 51 * For an int vector this is 204 bytes of memory for data buffer * and 7 bytes for validity buffer. @@ -805,7 +805,7 @@ public void testSetInitialCapacity() { assertEquals(512, vector.getValueCapacity()); assertTrue(vector.getDataVector().getValueCapacity() >= 51); - /** + /* * inner value capacity we pass to data vector is 512 * 0.01 => 5 * For an int vector this is 20 bytes of memory for data buffer * and 1 byte for validity buffer. @@ -818,7 +818,7 @@ public void testSetInitialCapacity() { assertEquals(512, vector.getValueCapacity()); assertTrue(vector.getDataVector().getValueCapacity() >= 5); - /** + /* * inner value capacity we pass to data vector is 5 * 0.1 => 0 * which is then rounded off to 1. So we pass value count as 1 * to the inner int vector. @@ -854,11 +854,11 @@ public void testClearAndReuse() { Object result = vector.getObject(0); ArrayList resultSet = (ArrayList) result; - assertEquals(new Long(7), resultSet.get(0)); + assertEquals(Long.valueOf(7), resultSet.get(0)); result = vector.getObject(1); resultSet = (ArrayList) result; - assertEquals(new Long(8), resultSet.get(0)); + assertEquals(Long.valueOf(8), resultSet.get(0)); // Clear and release the buffers to trigger a realloc when adding next value vector.clear(); @@ -874,11 +874,11 @@ public void testClearAndReuse() { result = vector.getObject(0); resultSet = (ArrayList) result; - assertEquals(new Long(7), resultSet.get(0)); + assertEquals(Long.valueOf(7), resultSet.get(0)); result = vector.getObject(1); resultSet = (ArrayList) result; - assertEquals(new Long(8), resultSet.get(0)); + assertEquals(Long.valueOf(8), resultSet.get(0)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java b/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java index c0a3bd89dc1..62fa0336ea9 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; @@ -52,11 +51,6 @@ public void init() { allocator = new RootAllocator(Long.MAX_VALUE); } - private static final Charset utf8Charset = Charset.forName("UTF-8"); - private static final byte[] STR1 = "AAAAA1".getBytes(utf8Charset); - private static final byte[] STR2 = "BBBBBBBBB2".getBytes(utf8Charset); - private static final byte[] STR3 = "CCCC3".getBytes(utf8Charset); - @After public void terminate() throws Exception { allocator.close(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java index 4c8c96a0d74..b7fc681c161 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java @@ -24,6 +24,8 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; +import java.util.Objects; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; @@ -413,8 +415,8 @@ public void testPromoteLargeVarCharHelpersOnStruct() throws Exception { writer.end(); final LargeVarCharVector uv = v.getChild("c", LargeVarCharVector.class); - assertEquals("foo", uv.getObject(0).toString()); - assertEquals("foo2", uv.getObject(1).toString()); + assertEquals("foo", Objects.requireNonNull(uv.getObject(0)).toString()); + assertEquals("foo2", Objects.requireNonNull(uv.getObject(1)).toString()); } } @@ -433,8 +435,8 @@ public void testPromoteVarCharHelpersOnStruct() throws Exception { writer.end(); final VarCharVector uv = v.getChild("c", VarCharVector.class); - assertEquals("foo", uv.getObject(0).toString()); - assertEquals("foo2", uv.getObject(1).toString()); + assertEquals("foo", Objects.requireNonNull(uv.getObject(0)).toString()); + assertEquals("foo2", Objects.requireNonNull(uv.getObject(1)).toString()); } } @@ -455,8 +457,8 @@ public void testPromoteVarCharHelpersDirect() throws Exception { // The "test" vector in the parent container should have been replaced with a UnionVector. UnionVector promotedVector = container.getChild("test", UnionVector.class); VarCharVector vector = promotedVector.getVarCharVector(); - assertEquals("foo", vector.getObject(0).toString()); - assertEquals("foo2", vector.getObject(1).toString()); + assertEquals("foo", Objects.requireNonNull(vector.getObject(0)).toString()); + assertEquals("foo2", Objects.requireNonNull(vector.getObject(1)).toString()); } } @@ -477,8 +479,8 @@ public void testPromoteLargeVarCharHelpersDirect() throws Exception { // The "test" vector in the parent container should have been replaced with a UnionVector. UnionVector promotedVector = container.getChild("test", UnionVector.class); LargeVarCharVector vector = promotedVector.getLargeVarCharVector(); - assertEquals("foo", vector.getObject(0).toString()); - assertEquals("foo2", vector.getObject(1).toString()); + assertEquals("foo", Objects.requireNonNull(vector.getObject(0)).toString()); + assertEquals("foo2", Objects.requireNonNull(vector.getObject(1)).toString()); } } @@ -491,20 +493,22 @@ public void testPromoteVarBinaryHelpersOnStruct() throws Exception { writer.start(); writer.setPosition(0); - writer.varBinary("c").writeVarBinary("row1".getBytes()); + writer.varBinary("c").writeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); writer.setPosition(1); - writer.varBinary("c").writeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + writer.varBinary("c").writeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); writer.setPosition(2); - writer.varBinary("c").writeVarBinary(ByteBuffer.wrap("row3".getBytes())); + writer.varBinary("c").writeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); writer.setPosition(3); - writer.varBinary("c").writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + writer.varBinary("c").writeVarBinary(ByteBuffer.wrap("row4".getBytes(StandardCharsets.UTF_8)), 0, + "row4".getBytes(StandardCharsets.UTF_8).length); writer.end(); final VarBinaryVector uv = v.getChild("c", VarBinaryVector.class); - assertEquals("row1", new String(uv.get(0))); - assertEquals("row2", new String(uv.get(1))); - assertEquals("row3", new String(uv.get(2))); - assertEquals("row4", new String(uv.get(3))); + assertEquals("row1", new String(Objects.requireNonNull(uv.get(0)), StandardCharsets.UTF_8)); + assertEquals("row2", new String(Objects.requireNonNull(uv.get(1)), StandardCharsets.UTF_8)); + assertEquals("row3", new String(Objects.requireNonNull(uv.get(2)), StandardCharsets.UTF_8)); + assertEquals("row4", new String(Objects.requireNonNull(uv.get(3)), StandardCharsets.UTF_8)); } } @@ -517,22 +521,24 @@ public void testPromoteVarBinaryHelpersDirect() throws Exception { writer.start(); writer.setPosition(0); - writer.writeVarBinary("row1".getBytes()); + writer.writeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); writer.setPosition(1); - writer.writeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + writer.writeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); writer.setPosition(2); - writer.writeVarBinary(ByteBuffer.wrap("row3".getBytes())); + writer.writeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); writer.setPosition(3); - writer.writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + writer.writeVarBinary(ByteBuffer.wrap("row4".getBytes(StandardCharsets.UTF_8)), 0, + "row4".getBytes(StandardCharsets.UTF_8).length); writer.end(); // The "test" vector in the parent container should have been replaced with a UnionVector. UnionVector promotedVector = container.getChild("test", UnionVector.class); VarBinaryVector uv = promotedVector.getVarBinaryVector(); - assertEquals("row1", new String(uv.get(0))); - assertEquals("row2", new String(uv.get(1))); - assertEquals("row3", new String(uv.get(2))); - assertEquals("row4", new String(uv.get(3))); + assertEquals("row1", new String(Objects.requireNonNull(uv.get(0)), StandardCharsets.UTF_8)); + assertEquals("row2", new String(Objects.requireNonNull(uv.get(1)), StandardCharsets.UTF_8)); + assertEquals("row3", new String(Objects.requireNonNull(uv.get(2)), StandardCharsets.UTF_8)); + assertEquals("row4", new String(Objects.requireNonNull(uv.get(3)), StandardCharsets.UTF_8)); } } @@ -545,20 +551,22 @@ public void testPromoteLargeVarBinaryHelpersOnStruct() throws Exception { writer.start(); writer.setPosition(0); - writer.largeVarBinary("c").writeLargeVarBinary("row1".getBytes()); + writer.largeVarBinary("c").writeLargeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); writer.setPosition(1); - writer.largeVarBinary("c").writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + writer.largeVarBinary("c").writeLargeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); writer.setPosition(2); - writer.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes())); + writer.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); writer.setPosition(3); - writer.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + writer.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes(StandardCharsets.UTF_8)), 0, + "row4".getBytes(StandardCharsets.UTF_8).length); writer.end(); final LargeVarBinaryVector uv = v.getChild("c", LargeVarBinaryVector.class); - assertEquals("row1", new String(uv.get(0))); - assertEquals("row2", new String(uv.get(1))); - assertEquals("row3", new String(uv.get(2))); - assertEquals("row4", new String(uv.get(3))); + assertEquals("row1", new String(Objects.requireNonNull(uv.get(0)), StandardCharsets.UTF_8)); + assertEquals("row2", new String(Objects.requireNonNull(uv.get(1)), StandardCharsets.UTF_8)); + assertEquals("row3", new String(Objects.requireNonNull(uv.get(2)), StandardCharsets.UTF_8)); + assertEquals("row4", new String(Objects.requireNonNull(uv.get(3)), StandardCharsets.UTF_8)); } } @@ -571,22 +579,24 @@ public void testPromoteLargeVarBinaryHelpersDirect() throws Exception { writer.start(); writer.setPosition(0); - writer.writeLargeVarBinary("row1".getBytes()); + writer.writeLargeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); writer.setPosition(1); - writer.writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + writer.writeLargeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); writer.setPosition(2); - writer.writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes())); + writer.writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); writer.setPosition(3); - writer.writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + writer.writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes(StandardCharsets.UTF_8)), 0, + "row4".getBytes(StandardCharsets.UTF_8).length); writer.end(); // The "test" vector in the parent container should have been replaced with a UnionVector. UnionVector promotedVector = container.getChild("test", UnionVector.class); LargeVarBinaryVector uv = promotedVector.getLargeVarBinaryVector(); - assertEquals("row1", new String(uv.get(0))); - assertEquals("row2", new String(uv.get(1))); - assertEquals("row3", new String(uv.get(2))); - assertEquals("row4", new String(uv.get(3))); + assertEquals("row1", new String(Objects.requireNonNull(uv.get(0)), StandardCharsets.UTF_8)); + assertEquals("row2", new String(Objects.requireNonNull(uv.get(1)), StandardCharsets.UTF_8)); + assertEquals("row3", new String(Objects.requireNonNull(uv.get(2)), StandardCharsets.UTF_8)); + assertEquals("row4", new String(Objects.requireNonNull(uv.get(3)), StandardCharsets.UTF_8)); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java index 9348cd3a667..145bdd588e9 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java @@ -79,8 +79,8 @@ public void testStreamZeroLengthBatch() throws IOException { VectorSchemaRoot root = reader.getVectorSchemaRoot(); IntVector vector = (IntVector) root.getFieldVectors().get(0); reader.loadNextBatch(); - assertEquals(vector.getValueCount(), 0); - assertEquals(root.getRowCount(), 0); + assertEquals(0, vector.getValueCount()); + assertEquals(0, root.getRowCount()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java index 6aa7a0c6df5..ac95121eb73 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java @@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.channels.Channels; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -138,7 +139,7 @@ private void readData( VarCharVector dictVector = (VarCharVector) dictionary.getVector(); assertEquals(expectedDictItems.length, dictVector.getValueCount()); for (int i = 0; i < dictVector.getValueCount(); i++) { - assertArrayEquals(expectedDictItems[i].getBytes(), dictVector.get(i)); + assertArrayEquals(expectedDictItems[i].getBytes(StandardCharsets.UTF_8), dictVector.get(i)); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java index ee5361547a0..0505a18484b 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java @@ -30,7 +30,7 @@ public void getMessageLength_returnsConstructValue() { // This API is used by spark. MessageMetadataResult result = new MessageMetadataResult(1, ByteBuffer.allocate(0), new org.apache.arrow.flatbuf.Message()); - assertEquals(result.getMessageLength(), 1); + assertEquals(1, result.getMessageLength()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java b/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java index 78f2ee51b89..1b7f984992a 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java @@ -28,8 +28,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -282,8 +284,8 @@ void testDecode() { VarCharVector dictionaryVector = new VarCharVector("dictionary", allocator); dictionaryVector.allocateNew(2); - dictionaryVector.set(0, "one".getBytes()); - dictionaryVector.set(1, "two".getBytes()); + dictionaryVector.set(0, "one".getBytes(StandardCharsets.UTF_8)); + dictionaryVector.set(1, "two".getBytes(StandardCharsets.UTF_8)); dictionaryVector.setValueCount(2); Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); @@ -297,8 +299,8 @@ void testDecode() { try (Table t = new Table(vectorList, vectorList.get(0).getValueCount(), provider)) { VarCharVector v = (VarCharVector) t.decode(encoded.getName(), 1L); assertNotNull(v); - assertEquals("one", new String(v.get(0))); - assertEquals("two", new String(v.get(1))); + assertEquals("one", new String(Objects.requireNonNull(v.get(0)), StandardCharsets.UTF_8)); + assertEquals("two", new String(Objects.requireNonNull(v.get(1)), StandardCharsets.UTF_8)); } } @@ -319,8 +321,8 @@ private DictionaryProvider getDictionary() { VarCharVector dictionaryVector = new VarCharVector("dictionary", allocator); dictionaryVector.allocateNew(2); - dictionaryVector.set(0, "one".getBytes()); - dictionaryVector.set(1, "two".getBytes()); + dictionaryVector.set(0, "one".getBytes(StandardCharsets.UTF_8)); + dictionaryVector.set(1, "two".getBytes(StandardCharsets.UTF_8)); dictionaryVector.setValueCount(2); Dictionary dictionary = new Dictionary(dictionaryVector, encoding); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java b/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java index cb0b7b8eb6b..c0b3bfdf732 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java @@ -20,6 +20,7 @@ import static org.apache.arrow.vector.complex.BaseRepeatedValueVector.OFFSET_WIDTH; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -117,8 +118,8 @@ static List intPlusVarcharColumns(BufferAllocator allocator) { IntVector v1 = getSimpleIntVector(allocator); VarCharVector v2 = new VarCharVector(VARCHAR_VECTOR_NAME_1, allocator); v2.allocateNew(2); - v2.set(0, "one".getBytes()); - v2.set(1, "two".getBytes()); + v2.set(0, "one".getBytes(StandardCharsets.UTF_8)); + v2.set(1, "two".getBytes(StandardCharsets.UTF_8)); v2.setValueCount(2); vectorList.add(v1); vectorList.add(v2); @@ -134,8 +135,8 @@ static List intPlusLargeVarcharColumns(BufferAllocator allocator) { IntVector v1 = getSimpleIntVector(allocator); LargeVarCharVector v2 = new LargeVarCharVector(VARCHAR_VECTOR_NAME_1, allocator); v2.allocateNew(2); - v2.set(0, "one".getBytes()); - v2.set(1, "two".getBytes()); + v2.set(0, "one".getBytes(StandardCharsets.UTF_8)); + v2.set(1, "two".getBytes(StandardCharsets.UTF_8)); v2.setValueCount(2); vectorList.add(v1); vectorList.add(v2); @@ -152,8 +153,8 @@ static List intPlusVarBinaryColumns(BufferAllocator allocator) { IntVector v1 = getSimpleIntVector(allocator); VarBinaryVector v2 = new VarBinaryVector(VARBINARY_VECTOR_NAME_1, allocator); v2.allocateNew(2); - v2.set(0, "one".getBytes()); - v2.set(1, "two".getBytes()); + v2.set(0, "one".getBytes(StandardCharsets.UTF_8)); + v2.set(1, "two".getBytes(StandardCharsets.UTF_8)); v2.setValueCount(2); vectorList.add(v1); vectorList.add(v2); @@ -170,8 +171,8 @@ static List intPlusLargeVarBinaryColumns(BufferAllocator allocator) IntVector v1 = getSimpleIntVector(allocator); LargeVarBinaryVector v2 = new LargeVarBinaryVector(VARBINARY_VECTOR_NAME_1, allocator); v2.allocateNew(2); - v2.set(0, "one".getBytes()); - v2.set(1, "two".getBytes()); + v2.set(0, "one".getBytes(StandardCharsets.UTF_8)); + v2.set(1, "two".getBytes(StandardCharsets.UTF_8)); v2.setValueCount(2); vectorList.add(v1); vectorList.add(v2); @@ -188,8 +189,8 @@ static List intPlusFixedBinaryColumns(BufferAllocator allocator) { IntVector v1 = getSimpleIntVector(allocator); FixedSizeBinaryVector v2 = new FixedSizeBinaryVector(FIXEDBINARY_VECTOR_NAME_1, allocator, 3); v2.allocateNew(2); - v2.set(0, "one".getBytes()); - v2.set(1, "two".getBytes()); + v2.set(0, "one".getBytes(StandardCharsets.UTF_8)); + v2.set(1, "two".getBytes(StandardCharsets.UTF_8)); v2.setValueCount(2); vectorList.add(v1); vectorList.add(v2); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java b/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java index 74257c45ca8..3c075c92930 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java @@ -20,6 +20,8 @@ import static junit.framework.TestCase.assertTrue; import static org.apache.arrow.vector.testing.ValueVectorDataPopulator.setVector; +import java.nio.charset.StandardCharsets; + import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BigIntVector; @@ -204,13 +206,14 @@ public void testPopulateFixedSizeBinaryVector() { if (i % 2 == 0) { vector1.setNull(i); } else { - vector1.set(i, ("test" + i).getBytes()); + vector1.set(i, ("test" + i).getBytes(StandardCharsets.UTF_8)); } } vector1.setValueCount(10); - setVector(vector2, null, "test1".getBytes(), null, "test3".getBytes(), null, "test5".getBytes(), null, - "test7".getBytes(), null, "test9".getBytes()); + setVector(vector2, null, "test1".getBytes(StandardCharsets.UTF_8), null, + "test3".getBytes(StandardCharsets.UTF_8), null, "test5".getBytes(StandardCharsets.UTF_8), null, + "test7".getBytes(StandardCharsets.UTF_8), null, "test9".getBytes(StandardCharsets.UTF_8)); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -571,13 +574,14 @@ public void testPopulateVarBinaryVector() { if (i % 2 == 0) { vector1.setNull(i); } else { - vector1.set(i, ("test" + i).getBytes()); + vector1.set(i, ("test" + i).getBytes(StandardCharsets.UTF_8)); } } vector1.setValueCount(10); - setVector(vector2, null, "test1".getBytes(), null, "test3".getBytes(), null, "test5".getBytes(), null, - "test7".getBytes(), null, "test9".getBytes()); + setVector(vector2, null, "test1".getBytes(StandardCharsets.UTF_8), null, + "test3".getBytes(StandardCharsets.UTF_8), null, "test5".getBytes(StandardCharsets.UTF_8), null, + "test7".getBytes(StandardCharsets.UTF_8), null, "test9".getBytes(StandardCharsets.UTF_8)); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -592,7 +596,7 @@ public void testPopulateVarCharVector() { if (i % 2 == 0) { vector1.setNull(i); } else { - vector1.set(i, ("test" + i).getBytes()); + vector1.set(i, ("test" + i).getBytes(StandardCharsets.UTF_8)); } } vector1.setValueCount(10); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java index b11aa5638d6..f562e63b4bf 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Base64; @@ -54,25 +55,27 @@ public void testSetByteArrayRepeatedly() { ReusableByteArray byteArray = new ReusableByteArray(); try (ArrowBuf workingBuf = allocator.buffer(100)) { final String str = "test"; - workingBuf.setBytes(0, str.getBytes()); - byteArray.set(workingBuf, 0, str.getBytes().length); - assertEquals(str.getBytes().length, byteArray.getLength()); - assertArrayEquals(str.getBytes(), Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); - assertEquals(Base64.getEncoder().encodeToString(str.getBytes()), byteArray.toString()); - assertEquals(new ReusableByteArray(str.getBytes()), byteArray); - assertEquals(new ReusableByteArray(str.getBytes()).hashCode(), byteArray.hashCode()); + workingBuf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); + byteArray.set(workingBuf, 0, str.getBytes(StandardCharsets.UTF_8).length); + assertEquals(str.getBytes(StandardCharsets.UTF_8).length, byteArray.getLength()); + assertArrayEquals(str.getBytes(StandardCharsets.UTF_8), Arrays.copyOfRange(byteArray.getBuffer(), 0, + (int) byteArray.getLength())); + assertEquals(Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)), byteArray.toString()); + assertEquals(new ReusableByteArray(str.getBytes(StandardCharsets.UTF_8)), byteArray); + assertEquals(new ReusableByteArray(str.getBytes(StandardCharsets.UTF_8)).hashCode(), byteArray.hashCode()); // Test a longer string. Should require reallocation. final String str2 = "test_longer"; byte[] oldBuffer = byteArray.getBuffer(); workingBuf.clear(); - workingBuf.setBytes(0, str2.getBytes()); - byteArray.set(workingBuf, 0, str2.getBytes().length); - assertEquals(str2.getBytes().length, byteArray.getLength()); - assertArrayEquals(str2.getBytes(), Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); - assertEquals(Base64.getEncoder().encodeToString(str2.getBytes()), byteArray.toString()); - assertEquals(new ReusableByteArray(str2.getBytes()), byteArray); - assertEquals(new ReusableByteArray(str2.getBytes()).hashCode(), byteArray.hashCode()); + workingBuf.setBytes(0, str2.getBytes(StandardCharsets.UTF_8)); + byteArray.set(workingBuf, 0, str2.getBytes(StandardCharsets.UTF_8).length); + assertEquals(str2.getBytes(StandardCharsets.UTF_8).length, byteArray.getLength()); + assertArrayEquals(str2.getBytes(StandardCharsets.UTF_8), Arrays.copyOfRange(byteArray.getBuffer(), 0, + (int) byteArray.getLength())); + assertEquals(Base64.getEncoder().encodeToString(str2.getBytes(StandardCharsets.UTF_8)), byteArray.toString()); + assertEquals(new ReusableByteArray(str2.getBytes(StandardCharsets.UTF_8)), byteArray); + assertEquals(new ReusableByteArray(str2.getBytes(StandardCharsets.UTF_8)).hashCode(), byteArray.hashCode()); // Verify reallocation needed. assertNotSame(oldBuffer, byteArray.getBuffer()); @@ -82,13 +85,14 @@ public void testSetByteArrayRepeatedly() { final String str3 = "short"; oldBuffer = byteArray.getBuffer(); workingBuf.clear(); - workingBuf.setBytes(0, str3.getBytes()); - byteArray.set(workingBuf, 0, str3.getBytes().length); - assertEquals(str3.getBytes().length, byteArray.getLength()); - assertArrayEquals(str3.getBytes(), Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); - assertEquals(Base64.getEncoder().encodeToString(str3.getBytes()), byteArray.toString()); - assertEquals(new ReusableByteArray(str3.getBytes()), byteArray); - assertEquals(new ReusableByteArray(str3.getBytes()).hashCode(), byteArray.hashCode()); + workingBuf.setBytes(0, str3.getBytes(StandardCharsets.UTF_8)); + byteArray.set(workingBuf, 0, str3.getBytes(StandardCharsets.UTF_8).length); + assertEquals(str3.getBytes(StandardCharsets.UTF_8).length, byteArray.getLength()); + assertArrayEquals(str3.getBytes(StandardCharsets.UTF_8), Arrays.copyOfRange(byteArray.getBuffer(), 0, + (int) byteArray.getLength())); + assertEquals(Base64.getEncoder().encodeToString(str3.getBytes(StandardCharsets.UTF_8)), byteArray.toString()); + assertEquals(new ReusableByteArray(str3.getBytes(StandardCharsets.UTF_8)), byteArray); + assertEquals(new ReusableByteArray(str3.getBytes(StandardCharsets.UTF_8)).hashCode(), byteArray.hashCode()); // Verify reallocation was not needed. assertSame(oldBuffer, byteArray.getBuffer()); From 3ad3b2d53ae0bfb59055f10a59a76896838e2cb7 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Wed, 17 Jan 2024 12:55:11 +0530 Subject: [PATCH 17/23] fixing warnings v17: vector s5 --- .../arrow/vector/ITTestLargeVector.java | 11 +- .../vector/TestBufferOwnershipTransfer.java | 4 +- .../org/apache/arrow/vector/TestCopyFrom.java | 7 +- .../arrow/vector/TestDecimal256Vector.java | 4 +- .../arrow/vector/TestDecimalVector.java | 4 +- .../arrow/vector/TestDenseUnionVector.java | 14 +- .../arrow/vector/TestDictionaryVector.java | 6 +- .../arrow/vector/TestLargeListVector.java | 122 +++++++++--------- .../apache/arrow/vector/TestMapVector.java | 34 ++--- .../arrow/vector/TestSplitAndTransfer.java | 7 +- .../apache/arrow/vector/TestUnionVector.java | 10 +- .../apache/arrow/vector/TestValueVector.java | 61 ++++----- .../arrow/vector/TestVarCharListVector.java | 10 +- .../apache/arrow/vector/TestVectorAlloc.java | 4 +- .../arrow/vector/TestVectorReAlloc.java | 4 +- .../arrow/vector/TestVectorSchemaRoot.java | 2 +- .../complex/writer/TestComplexWriter.java | 122 ++++++++++-------- .../apache/arrow/vector/ipc/BaseFileTest.java | 14 +- .../apache/arrow/vector/ipc/TestJSONFile.java | 4 +- .../apache/arrow/vector/table/RowTest.java | 14 +- .../vector/types/pojo/TestExtensionType.java | 4 +- .../TestElementAddressableVectorIterator.java | 6 +- .../arrow/vector/util/TestVectorAppender.java | 2 - 23 files changed, 238 insertions(+), 232 deletions(-) diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ITTestLargeVector.java b/java/vector/src/test/java/org/apache/arrow/vector/ITTestLargeVector.java index 19648dc9e13..8596399e7e0 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ITTestLargeVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ITTestLargeVector.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; @@ -133,7 +134,7 @@ public void testLargeDecimalVector() { for (int i = 0; i < vecLength; i++) { ArrowBuf buf = largeVec.get(i); - assertEquals(buf.capacity(), DecimalVector.TYPE_WIDTH); + assertEquals(DecimalVector.TYPE_WIDTH, buf.capacity()); assertEquals(0, buf.getLong(0)); assertEquals(0, buf.getLong(8)); @@ -215,7 +216,7 @@ public void testLargeVarCharVector() { logger.trace("Successfully allocated a vector with capacity " + vecLength); for (int i = 0; i < vecLength; i++) { - largeVec.setSafe(i, strElement.getBytes()); + largeVec.setSafe(i, strElement.getBytes(StandardCharsets.UTF_8)); if ((i + 1) % 10000 == 0) { logger.trace("Successfully written " + (i + 1) + " values"); @@ -228,7 +229,7 @@ public void testLargeVarCharVector() { for (int i = 0; i < vecLength; i++) { byte[] val = largeVec.get(i); - assertEquals(strElement, new String(val)); + assertEquals(strElement, new String(val, StandardCharsets.UTF_8)); if ((i + 1) % 10000 == 0) { logger.trace("Successfully read " + (i + 1) + " values"); @@ -254,7 +255,7 @@ public void testLargeLargeVarCharVector() { logger.trace("Successfully allocated a vector with capacity " + vecLength); for (int i = 0; i < vecLength; i++) { - largeVec.setSafe(i, strElement.getBytes()); + largeVec.setSafe(i, strElement.getBytes(StandardCharsets.UTF_8)); if ((i + 1) % 10000 == 0) { logger.trace("Successfully written " + (i + 1) + " values"); @@ -267,7 +268,7 @@ public void testLargeLargeVarCharVector() { for (int i = 0; i < vecLength; i++) { byte[] val = largeVec.get(i); - assertEquals(strElement, new String(val)); + assertEquals(strElement, new String(val, StandardCharsets.UTF_8)); if ((i + 1) % 10000 == 0) { logger.trace("Successfully read " + (i + 1) + " values"); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java b/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java index 8efadad9b3b..056b6bdd2b7 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java @@ -21,6 +21,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.nio.charset.StandardCharsets; + import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.ReferenceManager; import org.apache.arrow.memory.RootAllocator; @@ -65,7 +67,7 @@ public void testTransferVariableWidth() { VarCharVector v1 = new VarCharVector("v1", childAllocator1); v1.allocateNew(); - v1.setSafe(4094, "hello world".getBytes(), 0, 11); + v1.setSafe(4094, "hello world".getBytes(StandardCharsets.UTF_8), 0, 11); v1.setValueCount(4001); VarCharVector v2 = new VarCharVector("v2", childAllocator2); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java index 873e3e47df9..97de27bec82 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java @@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Period; +import java.util.Objects; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -1084,11 +1085,11 @@ public void testCopySafeArrow7837() { vc1.setSafe(0, "1234567890".getBytes(StandardCharsets.UTF_8)); assertFalse(vc1.isNull(0)); - assertEquals(vc1.getObject(0).toString(), "1234567890"); + assertEquals("1234567890", Objects.requireNonNull(vc1.getObject(0)).toString()); vc2.copyFromSafe(0, 0, vc1); assertFalse(vc2.isNull(0)); - assertEquals(vc2.getObject(0).toString(), "1234567890"); + assertEquals("1234567890", Objects.requireNonNull(vc2.getObject(0)).toString()); vc2.copyFromSafe(0, 5, vc1); assertTrue(vc2.isNull(1)); @@ -1096,7 +1097,7 @@ public void testCopySafeArrow7837() { assertTrue(vc2.isNull(3)); assertTrue(vc2.isNull(4)); assertFalse(vc2.isNull(5)); - assertEquals(vc2.getObject(5).toString(), "1234567890"); + assertEquals("1234567890", Objects.requireNonNull(vc2.getObject(5)).toString()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java index b703959d2bb..fc5dfc38587 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java @@ -40,8 +40,8 @@ public class TestDecimal256Vector { static { intValues = new long[60]; for (int i = 0; i < intValues.length / 2; i++) { - intValues[i] = 1 << i + 1; - intValues[2 * i] = -1 * (1 << i + 1); + intValues[i] = 1L << (i + 1); + intValues[2 * i] = -1L * (1 << (i + 1)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java index ba25cbe8b52..572f13fea1e 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java @@ -40,8 +40,8 @@ public class TestDecimalVector { static { intValues = new long[60]; for (int i = 0; i < intValues.length / 2; i++) { - intValues[i] = 1 << i + 1; - intValues[2 * i] = -1 * (1 << i + 1); + intValues[i] = 1L << (i + 1); + intValues[2 * i] = -1L * (1 << (i + 1)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java index 9cb12481612..8fd33eb5a84 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java @@ -349,16 +349,16 @@ public void testGetFieldTypeInfo() throws Exception { assertEquals(vector.getField(), field); // Union has 2 child vectors - assertEquals(vector.size(), 2); + assertEquals(2, vector.size()); // Check child field 0 VectorWithOrdinal intChild = vector.getChildVectorWithOrdinal("int"); - assertEquals(intChild.ordinal, 0); + assertEquals(0, intChild.ordinal); assertEquals(intChild.vector.getField(), children.get(0)); // Check child field 1 VectorWithOrdinal varcharChild = vector.getChildVectorWithOrdinal("varchar"); - assertEquals(varcharChild.ordinal, 1); + assertEquals(1, varcharChild.ordinal); assertEquals(varcharChild.vector.getField(), children.get(1)); } @@ -458,8 +458,8 @@ public void testMultipleStructs() { // register relative types byte typeId1 = unionVector.registerNewTypeId(structVector1.getField()); byte typeId2 = unionVector.registerNewTypeId(structVector2.getField()); - assertEquals(typeId1, 0); - assertEquals(typeId2, 1); + assertEquals(0, typeId1); + assertEquals(1, typeId2); // add two struct vectors to union vector unionVector.addVector(typeId1, structVector1); @@ -519,8 +519,8 @@ public void testMultipleVarChars() { byte typeId1 = unionVector.registerNewTypeId(childVector1.getField()); byte typeId2 = unionVector.registerNewTypeId(childVector2.getField()); - assertEquals(typeId1, 0); - assertEquals(typeId2, 1); + assertEquals(0, typeId1); + assertEquals(1, typeId2); while (unionVector.getValueCapacity() < 5) { unionVector.reAlloc(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java index 17758f6b414..9ffa79470ee 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java @@ -552,7 +552,7 @@ public void testEncodeWithEncoderInstance() { // now run through the decoder and verify we get the original back try (ValueVector decoded = encoder.decode(encoded)) { assertEquals(vector.getClass(), decoded.getClass()); - assertEquals(vector.getValueCount(), (decoded).getValueCount()); + assertEquals(vector.getValueCount(), decoded.getValueCount()); for (int i = 0; i < 5; i++) { assertEquals(vector.getObject(i), ((VarCharVector) decoded).getObject(i)); } @@ -591,7 +591,7 @@ public void testEncodeMultiVectors() { // now run through the decoder and verify we get the original back try (ValueVector decoded = encoder.decode(encoded)) { assertEquals(vector1.getClass(), decoded.getClass()); - assertEquals(vector1.getValueCount(), (decoded).getValueCount()); + assertEquals(vector1.getValueCount(), decoded.getValueCount()); for (int i = 0; i < 5; i++) { assertEquals(vector1.getObject(i), ((VarCharVector) decoded).getObject(i)); } @@ -611,7 +611,7 @@ public void testEncodeMultiVectors() { // now run through the decoder and verify we get the original back try (ValueVector decoded = encoder.decode(encoded)) { assertEquals(vector2.getClass(), decoded.getClass()); - assertEquals(vector2.getValueCount(), (decoded).getValueCount()); + assertEquals(vector2.getValueCount(), decoded.getValueCount()); for (int i = 0; i < 3; i++) { assertEquals(vector2.getObject(i), ((VarCharVector) decoded).getObject(i)); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java index 993ce0b0897..78cd77d1619 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java @@ -102,9 +102,9 @@ public void testCopyFrom() throws Exception { Object result = outVector.getObject(0); ArrayList resultSet = (ArrayList) result; assertEquals(3, resultSet.size()); - assertEquals(new Long(1), resultSet.get(0)); - assertEquals(new Long(2), resultSet.get(1)); - assertEquals(new Long(3), resultSet.get(2)); + assertEquals(Long.valueOf(1), resultSet.get(0)); + assertEquals(Long.valueOf(2), resultSet.get(1)); + assertEquals(Long.valueOf(3), resultSet.get(2)); /* index 1 */ result = outVector.getObject(1); @@ -143,7 +143,7 @@ public void testSetLastSetUsage() throws Exception { assertEquals(-1L, listVector.getLastSet()); int index = 0; - int offset = 0; + int offset; /* write [10, 11, 12] to the list vector at index 0 */ BitVectorHelper.setBit(validityBuffer, index); @@ -222,36 +222,36 @@ public void testSetLastSetUsage() throws Exception { assertEquals(Integer.toString(0), Integer.toString(offset)); Long actual = dataVector.getObject(offset); - assertEquals(new Long(10), actual); + assertEquals(Long.valueOf(10), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(11), actual); + assertEquals(Long.valueOf(11), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(12), actual); + assertEquals(Long.valueOf(12), actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(3), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(13), actual); + assertEquals(Long.valueOf(13), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(14), actual); + assertEquals(Long.valueOf(14), actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(5), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(15), actual); + assertEquals(Long.valueOf(15), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(16), actual); + assertEquals(Long.valueOf(16), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(17), actual); + assertEquals(Long.valueOf(17), actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); @@ -323,8 +323,8 @@ public void testSplitAndTransfer() throws Exception { /* check the vector output */ int index = 0; - int offset = 0; - Long actual = null; + int offset; + Long actual; /* index 0 */ assertFalse(listVector.isNull(index)); @@ -332,13 +332,13 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(0), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(10), actual); + assertEquals(Long.valueOf(10), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(11), actual); + assertEquals(Long.valueOf(11), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(12), actual); + assertEquals(Long.valueOf(12), actual); /* index 1 */ index++; @@ -347,10 +347,10 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(3), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(13), actual); + assertEquals(Long.valueOf(13), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(14), actual); + assertEquals(Long.valueOf(14), actual); /* index 2 */ index++; @@ -359,16 +359,16 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(5), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(15), actual); + assertEquals(Long.valueOf(15), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(16), actual); + assertEquals(Long.valueOf(16), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(17), actual); + assertEquals(Long.valueOf(17), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(18), actual); + assertEquals(Long.valueOf(18), actual); /* index 3 */ index++; @@ -377,7 +377,7 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(9), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(19), actual); + assertEquals(Long.valueOf(19), actual); /* index 4 */ index++; @@ -386,16 +386,16 @@ public void testSplitAndTransfer() throws Exception { assertEquals(Integer.toString(10), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(new Long(20), actual); + assertEquals(Long.valueOf(20), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(21), actual); + assertEquals(Long.valueOf(21), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(22), actual); + assertEquals(Long.valueOf(22), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(new Long(23), actual); + assertEquals(Long.valueOf(23), actual); /* index 5 */ index++; @@ -522,15 +522,15 @@ public void testNestedLargeListVector() throws Exception { assertEquals(4, resultSet.get(1).size()); /* size of second inner list */ list = resultSet.get(0); - assertEquals(new Long(50), list.get(0)); - assertEquals(new Long(100), list.get(1)); - assertEquals(new Long(200), list.get(2)); + assertEquals(Long.valueOf(50), list.get(0)); + assertEquals(Long.valueOf(100), list.get(1)); + assertEquals(Long.valueOf(200), list.get(2)); list = resultSet.get(1); - assertEquals(new Long(75), list.get(0)); - assertEquals(new Long(125), list.get(1)); - assertEquals(new Long(150), list.get(2)); - assertEquals(new Long(175), list.get(3)); + assertEquals(Long.valueOf(75), list.get(0)); + assertEquals(Long.valueOf(125), list.get(1)); + assertEquals(Long.valueOf(150), list.get(2)); + assertEquals(Long.valueOf(175), list.get(3)); /* get listVector value at index 1 -- the value itself is a listvector */ result = listVector.getObject(1); @@ -542,16 +542,16 @@ public void testNestedLargeListVector() throws Exception { assertEquals(3, resultSet.get(2).size()); /* size of third inner list */ list = resultSet.get(0); - assertEquals(new Long(10), list.get(0)); + assertEquals(Long.valueOf(10), list.get(0)); list = resultSet.get(1); - assertEquals(new Long(15), list.get(0)); - assertEquals(new Long(20), list.get(1)); + assertEquals(Long.valueOf(15), list.get(0)); + assertEquals(Long.valueOf(20), list.get(1)); list = resultSet.get(2); - assertEquals(new Long(25), list.get(0)); - assertEquals(new Long(30), list.get(1)); - assertEquals(new Long(35), list.get(2)); + assertEquals(Long.valueOf(25), list.get(0)); + assertEquals(Long.valueOf(30), list.get(1)); + assertEquals(Long.valueOf(35), list.get(2)); /* check underlying bitVector */ assertFalse(listVector.isNull(0)); @@ -656,13 +656,13 @@ public void testNestedLargeListVector2() throws Exception { assertEquals(2, resultSet.get(1).size()); /* size of second inner list */ list = resultSet.get(0); - assertEquals(new Long(50), list.get(0)); - assertEquals(new Long(100), list.get(1)); - assertEquals(new Long(200), list.get(2)); + assertEquals(Long.valueOf(50), list.get(0)); + assertEquals(Long.valueOf(100), list.get(1)); + assertEquals(Long.valueOf(200), list.get(2)); list = resultSet.get(1); - assertEquals(new Long(75), list.get(0)); - assertEquals(new Long(125), list.get(1)); + assertEquals(Long.valueOf(75), list.get(0)); + assertEquals(Long.valueOf(125), list.get(1)); /* get listVector value at index 1 -- the value itself is a listvector */ result = listVector.getObject(1); @@ -673,13 +673,13 @@ public void testNestedLargeListVector2() throws Exception { assertEquals(3, resultSet.get(1).size()); /* size of second inner list */ list = resultSet.get(0); - assertEquals(new Long(15), list.get(0)); - assertEquals(new Long(20), list.get(1)); + assertEquals(Long.valueOf(15), list.get(0)); + assertEquals(Long.valueOf(20), list.get(1)); list = resultSet.get(1); - assertEquals(new Long(25), list.get(0)); - assertEquals(new Long(30), list.get(1)); - assertEquals(new Long(35), list.get(2)); + assertEquals(Long.valueOf(25), list.get(0)); + assertEquals(Long.valueOf(30), list.get(1)); + assertEquals(Long.valueOf(35), list.get(2)); /* check underlying bitVector */ assertFalse(listVector.isNull(0)); @@ -723,15 +723,15 @@ public void testGetBufferAddress() throws Exception { Object result = listVector.getObject(0); ArrayList resultSet = (ArrayList) result; assertEquals(3, resultSet.size()); - assertEquals(new Long(50), resultSet.get(0)); - assertEquals(new Long(100), resultSet.get(1)); - assertEquals(new Long(200), resultSet.get(2)); + assertEquals(Long.valueOf(50), resultSet.get(0)); + assertEquals(Long.valueOf(100), resultSet.get(1)); + assertEquals(Long.valueOf(200), resultSet.get(2)); result = listVector.getObject(1); resultSet = (ArrayList) result; assertEquals(2, resultSet.size()); - assertEquals(new Long(250), resultSet.get(0)); - assertEquals(new Long(300), resultSet.get(1)); + assertEquals(Long.valueOf(250), resultSet.get(0)); + assertEquals(Long.valueOf(300), resultSet.get(1)); List buffers = listVector.getFieldBuffers(); @@ -739,7 +739,7 @@ public void testGetBufferAddress() throws Exception { long offsetAddress = listVector.getOffsetBufferAddress(); try { - long dataAddress = listVector.getDataBufferAddress(); + listVector.getDataBufferAddress(); } catch (UnsupportedOperationException ue) { error = true; } finally { @@ -849,11 +849,11 @@ public void testClearAndReuse() { Object result = vector.getObject(0); ArrayList resultSet = (ArrayList) result; - assertEquals(new Long(7), resultSet.get(0)); + assertEquals(Long.valueOf(7), resultSet.get(0)); result = vector.getObject(1); resultSet = (ArrayList) result; - assertEquals(new Long(8), resultSet.get(0)); + assertEquals(Long.valueOf(8), resultSet.get(0)); // Clear and release the buffers to trigger a realloc when adding next value vector.clear(); @@ -869,11 +869,11 @@ public void testClearAndReuse() { result = vector.getObject(0); resultSet = (ArrayList) result; - assertEquals(new Long(7), resultSet.get(0)); + assertEquals(Long.valueOf(7), resultSet.get(0)); result = vector.getObject(1); resultSet = (ArrayList) result; - assertEquals(new Long(8), resultSet.get(0)); + assertEquals(Long.valueOf(8), resultSet.get(0)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java index 1db55198e4b..43f4c3b536f 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java @@ -335,8 +335,8 @@ public void testSplitAndTransfer() throws Exception { /* check the vector output */ int index = 0; - int offset = 0; - Map result = null; + int offset; + Map result; /* index 0 */ assertFalse(mapVector.isNull(index)); @@ -571,18 +571,18 @@ public void testMapWithListValue() throws Exception { assertEquals(1L, getResultKey(resultStruct)); ArrayList list = (ArrayList) getResultValue(resultStruct); assertEquals(3, list.size()); // value is a list with 3 elements - assertEquals(new Long(50), list.get(0)); - assertEquals(new Long(100), list.get(1)); - assertEquals(new Long(200), list.get(2)); + assertEquals(Long.valueOf(50), list.get(0)); + assertEquals(Long.valueOf(100), list.get(1)); + assertEquals(Long.valueOf(200), list.get(2)); // Second Map entry resultStruct = (Map) resultSet.get(1); list = (ArrayList) getResultValue(resultStruct); assertEquals(4, list.size()); // value is a list with 4 elements - assertEquals(new Long(75), list.get(0)); - assertEquals(new Long(125), list.get(1)); - assertEquals(new Long(150), list.get(2)); - assertEquals(new Long(175), list.get(3)); + assertEquals(Long.valueOf(75), list.get(0)); + assertEquals(Long.valueOf(125), list.get(1)); + assertEquals(Long.valueOf(150), list.get(2)); + assertEquals(Long.valueOf(175), list.get(3)); // Get mapVector element at index 1 result = mapVector.getObject(1); @@ -593,24 +593,24 @@ public void testMapWithListValue() throws Exception { assertEquals(3L, getResultKey(resultStruct)); list = (ArrayList) getResultValue(resultStruct); assertEquals(1, list.size()); // value is a list with 1 element - assertEquals(new Long(10), list.get(0)); + assertEquals(Long.valueOf(10), list.get(0)); // Second Map entry resultStruct = (Map) resultSet.get(1); assertEquals(4L, getResultKey(resultStruct)); list = (ArrayList) getResultValue(resultStruct); assertEquals(2, list.size()); // value is a list with 1 element - assertEquals(new Long(15), list.get(0)); - assertEquals(new Long(20), list.get(1)); + assertEquals(Long.valueOf(15), list.get(0)); + assertEquals(Long.valueOf(20), list.get(1)); // Third Map entry resultStruct = (Map) resultSet.get(2); assertEquals(5L, getResultKey(resultStruct)); list = (ArrayList) getResultValue(resultStruct); assertEquals(3, list.size()); // value is a list with 1 element - assertEquals(new Long(25), list.get(0)); - assertEquals(new Long(30), list.get(1)); - assertEquals(new Long(35), list.get(2)); + assertEquals(Long.valueOf(25), list.get(0)); + assertEquals(Long.valueOf(30), list.get(1)); + assertEquals(Long.valueOf(35), list.get(2)); /* check underlying bitVector */ assertFalse(mapVector.isNull(0)); @@ -1012,8 +1012,8 @@ public void testMapWithMapKeyAndMapValue() throws Exception { final ArrowBuf offsetBuffer = mapVector.getOffsetBuffer(); /* mapVector has 2 entries at index 0 and 4 entries at index 1 */ - assertEquals(0, offsetBuffer.getInt(0 * MapVector.OFFSET_WIDTH)); - assertEquals(2, offsetBuffer.getInt(1 * MapVector.OFFSET_WIDTH)); + assertEquals(0, offsetBuffer.getInt(0)); + assertEquals(2, offsetBuffer.getInt(MapVector.OFFSET_WIDTH)); assertEquals(6, offsetBuffer.getInt(2 * MapVector.OFFSET_WIDTH)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java b/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java index 716fa0bde45..3580a321f01 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -57,7 +58,7 @@ public void terminate() throws Exception { private void populateVarcharVector(final VarCharVector vector, int valueCount, String[] compareArray) { for (int i = 0; i < valueCount; i += 3) { final String s = String.format("%010d", i); - vector.set(i, s.getBytes()); + vector.set(i, s.getBytes(StandardCharsets.UTF_8)); if (compareArray != null) { compareArray[i] = s; } @@ -86,7 +87,7 @@ public void test() throws Exception { for (int i = 0; i < length; i++) { final boolean expectedSet = ((start + i) % 3) == 0; if (expectedSet) { - final byte[] expectedValue = compareArray[start + i].getBytes(); + final byte[] expectedValue = compareArray[start + i].getBytes(StandardCharsets.UTF_8); assertFalse(newVarCharVector.isNull(i)); assertArrayEquals(expectedValue, newVarCharVector.get(i)); } else { @@ -141,7 +142,7 @@ public void testTransfer() { for (int i = 0; i < valueCount; i++) { final boolean expectedSet = (i % 3) == 0; if (expectedSet) { - final byte[] expectedValue = compareArray[i].getBytes(); + final byte[] expectedValue = compareArray[i].getBytes(StandardCharsets.UTF_8); assertFalse(newVarCharVector.isNull(i)); assertArrayEquals(expectedValue, newVarCharVector.get(i)); } else { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java index b53171a5976..1b0387feb73 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java @@ -404,16 +404,16 @@ public void testGetFieldTypeInfo() throws Exception { assertTrue(vector.getField().equals(field)); // Union has 2 child vectors - assertEquals(vector.size(), 2); + assertEquals(2, vector.size()); // Check child field 0 VectorWithOrdinal intChild = vector.getChildVectorWithOrdinal("int"); - assertEquals(intChild.ordinal, 0); + assertEquals(0, intChild.ordinal); assertEquals(intChild.vector.getField(), children.get(0)); // Check child field 1 VectorWithOrdinal varcharChild = vector.getChildVectorWithOrdinal("varchar"); - assertEquals(varcharChild.ordinal, 1); + assertEquals(1, varcharChild.ordinal); assertEquals(varcharChild.vector.getField(), children.get(1)); } @@ -455,7 +455,7 @@ public void testGetBufferAddress() throws Exception { try { - long offsetAddress = vector.getOffsetBufferAddress(); + vector.getOffsetBufferAddress(); } catch (UnsupportedOperationException ue) { error = true; } finally { @@ -464,7 +464,7 @@ public void testGetBufferAddress() throws Exception { } try { - long dataAddress = vector.getDataBufferAddress(); + vector.getDataBufferAddress(); } catch (UnsupportedOperationException ue) { error = true; } finally { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java index fb968708044..614aff18d45 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java @@ -83,7 +83,7 @@ public void init() { allocator = new RootAllocator(Long.MAX_VALUE); } - private static final Charset utf8Charset = Charset.forName("UTF-8"); + private static final Charset utf8Charset = StandardCharsets.UTF_8; private static final byte[] STR1 = "AAAAA1".getBytes(utf8Charset); private static final byte[] STR2 = "BBBBBBBBB2".getBytes(utf8Charset); private static final byte[] STR3 = "CCCC3".getBytes(utf8Charset); @@ -127,10 +127,9 @@ public void testFixedType1() { try (final UInt4Vector vector = new UInt4Vector(EMPTY_SCHEMA_PATH, allocator)) { boolean error = false; - int initialCapacity = 0; vector.allocateNew(1024); - initialCapacity = vector.getValueCapacity(); + int initialCapacity = vector.getValueCapacity(); assertTrue(initialCapacity >= 1024); // Put and set a few values @@ -562,8 +561,6 @@ public void testNullableFixedType1() { assertEquals(103, vector.get(initialCapacity - 2)); assertEquals(104, vector.get(initialCapacity - 1)); - int val = 0; - /* check unset bits/null values */ for (int i = 2, j = 101; i <= 99 || j <= initialCapacity - 3; i++, j++) { if (i <= 99) { @@ -606,8 +603,6 @@ public void testNullableFixedType1() { assertEquals(104, vector.get(initialCapacity - 1)); assertEquals(10000, vector.get(initialCapacity)); - val = 0; - /* check unset bits/null values */ for (int i = 2, j = 101; i < 99 || j < initialCapacity - 3; i++, j++) { if (i <= 99) { @@ -735,7 +730,6 @@ public void testNullableFixedType2() { public void testNullableFixedType3() { // Create a new value vector for 1024 integers try (final IntVector vector = newVector(IntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, allocator)) { - boolean error = false; int initialCapacity = 1024; /* no memory allocation has happened yet so capacity of underlying buffer should be 0 */ @@ -765,7 +759,6 @@ public void testNullableFixedType3() { } vector.setValueCount(1024); - Field field = vector.getField(); List buffers = vector.getFieldBuffers(); @@ -1105,7 +1098,6 @@ public void testNullableVarType1() { assertEquals(txt, vector.getObject(7)); // Ensure null value throws. - boolean b = false; assertNull(vector.get(8)); } } @@ -1182,18 +1174,18 @@ public void testGetBytesRepeatedly() { final String str = "hello world"; final String str2 = "foo"; - vector.setSafe(0, str.getBytes()); - vector.setSafe(1, str2.getBytes()); + vector.setSafe(0, str.getBytes(StandardCharsets.UTF_8)); + vector.setSafe(1, str2.getBytes(StandardCharsets.UTF_8)); // verify results ReusableByteArray reusableByteArray = new ReusableByteArray(); vector.read(0, reusableByteArray); - assertArrayEquals(str.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), + assertArrayEquals(str.getBytes(StandardCharsets.UTF_8), Arrays.copyOfRange(reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); byte[] oldBuffer = reusableByteArray.getBuffer(); vector.read(1, reusableByteArray); - assertArrayEquals(str2.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), + assertArrayEquals(str2.getBytes(StandardCharsets.UTF_8), Arrays.copyOfRange(reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); // There should not have been any reallocation since the newer value is smaller in length. @@ -1219,7 +1211,6 @@ public void testGetBytesRepeatedly() { public void testReallocAfterVectorTransfer1() { try (final Float8Vector vector = new Float8Vector(EMPTY_SCHEMA_PATH, allocator)) { int initialCapacity = 4096; - boolean error = false; /* use the default capacity; 4096*8 => 32KB */ vector.setInitialCapacity(initialCapacity); @@ -1259,7 +1250,7 @@ public void testReallocAfterVectorTransfer1() { } /* this should trigger a realloc */ - vector.setSafe(capacityAfterRealloc1, baseValue + (double) (capacityAfterRealloc1)); + vector.setSafe(capacityAfterRealloc1, baseValue + (double) capacityAfterRealloc1); assertTrue(vector.getValueCapacity() >= initialCapacity * 4); int capacityAfterRealloc2 = vector.getValueCapacity(); @@ -1301,7 +1292,6 @@ public void testReallocAfterVectorTransfer1() { public void testReallocAfterVectorTransfer2() { try (final Float8Vector vector = new Float8Vector(EMPTY_SCHEMA_PATH, allocator)) { int initialCapacity = 4096; - boolean error = false; vector.allocateNew(initialCapacity); assertTrue(vector.getValueCapacity() >= initialCapacity); @@ -1338,7 +1328,7 @@ public void testReallocAfterVectorTransfer2() { } /* this should trigger a realloc */ - vector.setSafe(capacityAfterRealloc1, baseValue + (double) (capacityAfterRealloc1)); + vector.setSafe(capacityAfterRealloc1, baseValue + (double) capacityAfterRealloc1); assertTrue(vector.getValueCapacity() >= initialCapacity * 4); int capacityAfterRealloc2 = vector.getValueCapacity(); @@ -1494,7 +1484,6 @@ public void testReallocAfterVectorTransfer4() { assertTrue(valueCapacity >= 4096); /* populate the vector */ - int baseValue = 1000; for (int i = 0; i < valueCapacity; i++) { if ((i & 1) == 0) { vector.set(i, 1000 + i); @@ -1649,7 +1638,7 @@ public void testFillEmptiesNotOverfill() { int initialCapacity = vector.getValueCapacity(); assertTrue(initialCapacity >= 4095); - vector.setSafe(4094, "hello".getBytes(), 0, 5); + vector.setSafe(4094, "hello".getBytes(StandardCharsets.UTF_8), 0, 5); /* the above set method should NOT have triggered a realloc */ assertEquals(initialCapacity, vector.getValueCapacity()); @@ -1663,7 +1652,7 @@ public void testFillEmptiesNotOverfill() { @Test public void testSetSafeWithArrowBufNoExcessAllocs() { final int numValues = BaseFixedWidthVector.INITIAL_VALUE_ALLOCATION * 2; - final byte[] valueBytes = "hello world".getBytes(); + final byte[] valueBytes = "hello world".getBytes(StandardCharsets.UTF_8); final int valueBytesLength = valueBytes.length; final int isSet = 1; @@ -1720,7 +1709,7 @@ public void testCopyFromWithNulls() { if (i % 3 == 0) { continue; } - byte[] b = Integer.toString(i).getBytes(); + byte[] b = Integer.toString(i).getBytes(StandardCharsets.UTF_8); vector.setSafe(i, b, 0, b.length); } @@ -1781,7 +1770,7 @@ public void testCopyFromWithNulls1() { if (i % 3 == 0) { continue; } - byte[] b = Integer.toString(i).getBytes(); + byte[] b = Integer.toString(i).getBytes(StandardCharsets.UTF_8); vector.setSafe(i, b, 0, b.length); } @@ -2137,7 +2126,7 @@ public void testGetBufferAddress2() { long dataAddress = vector.getDataBufferAddress(); try { - long offsetAddress = vector.getOffsetBufferAddress(); + vector.getOffsetBufferAddress(); } catch (UnsupportedOperationException ue) { error = true; } finally { @@ -2275,7 +2264,7 @@ public void testSetNullableVarCharHolder() { String str = "hello"; ArrowBuf buf = allocator.buffer(16); - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); stringHolder.start = 0; stringHolder.end = str.length(); @@ -2286,7 +2275,7 @@ public void testSetNullableVarCharHolder() { // verify results assertTrue(vector.isNull(0)); - assertEquals(str, new String(vector.get(1))); + assertEquals(str, new String(vector.get(1), StandardCharsets.UTF_8)); buf.close(); } @@ -2305,7 +2294,7 @@ public void testSetNullableVarCharHolderSafe() { String str = "hello world"; ArrowBuf buf = allocator.buffer(16); - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); stringHolder.start = 0; stringHolder.end = str.length(); @@ -2315,7 +2304,7 @@ public void testSetNullableVarCharHolderSafe() { vector.setSafe(1, nullHolder); // verify results - assertEquals(str, new String(vector.get(0))); + assertEquals(str, new String(vector.get(0), StandardCharsets.UTF_8)); assertTrue(vector.isNull(1)); buf.close(); @@ -2335,7 +2324,7 @@ public void testSetNullableVarBinaryHolder() { String str = "hello"; ArrowBuf buf = allocator.buffer(16); - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); binHolder.start = 0; binHolder.end = str.length(); @@ -2346,7 +2335,7 @@ public void testSetNullableVarBinaryHolder() { // verify results assertTrue(vector.isNull(0)); - assertEquals(str, new String(vector.get(1))); + assertEquals(str, new String(vector.get(1), StandardCharsets.UTF_8)); buf.close(); } @@ -2365,7 +2354,7 @@ public void testSetNullableVarBinaryHolderSafe() { String str = "hello world"; ArrowBuf buf = allocator.buffer(16); - buf.setBytes(0, str.getBytes()); + buf.setBytes(0, str.getBytes(StandardCharsets.UTF_8)); binHolder.start = 0; binHolder.end = str.length(); @@ -2375,7 +2364,7 @@ public void testSetNullableVarBinaryHolderSafe() { vector.setSafe(1, nullHolder); // verify results - assertEquals(str, new String(vector.get(0))); + assertEquals(str, new String(vector.get(0), StandardCharsets.UTF_8)); assertTrue(vector.isNull(1)); buf.close(); @@ -2431,8 +2420,8 @@ public void testGetPointerVariableWidth() { for (int i = 0; i < sampleData.length; i++) { String str = sampleData[i]; if (str != null) { - vec1.set(i, sampleData[i].getBytes()); - vec2.set(i, sampleData[i].getBytes()); + vec1.set(i, sampleData[i].getBytes(StandardCharsets.UTF_8)); + vec2.set(i, sampleData[i].getBytes(StandardCharsets.UTF_8)); } else { vec1.setNull(i); vec2.setNull(i); @@ -2827,7 +2816,7 @@ public void testVariableWidthVectorNullHashCode() { varChVec.allocateNew(100, 1); varChVec.setValueCount(1); - varChVec.set(0, "abc".getBytes()); + varChVec.set(0, "abc".getBytes(StandardCharsets.UTF_8)); varChVec.setNull(0); assertEquals(0, varChVec.hashCode(0)); @@ -2945,7 +2934,7 @@ public void testUnloadVariableWidthVector() { varCharVector.allocateNew(5, 2); varCharVector.setValueCount(2); - varCharVector.set(0, "abcd".getBytes()); + varCharVector.set(0, "abcd".getBytes(StandardCharsets.UTF_8)); List bufs = varCharVector.getFieldBuffers(); assertEquals(3, bufs.size()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java index a9b155499f7..bfe489fa5af 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java @@ -17,6 +17,8 @@ package org.apache.arrow.vector; +import java.nio.charset.StandardCharsets; + import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.ListVector; @@ -44,7 +46,7 @@ public void terminate() throws Exception { @Test public void testVarCharListWithNulls() { - byte[] bytes = "a".getBytes(); + byte[] bytes = "a".getBytes(StandardCharsets.UTF_8); try (ListVector vector = new ListVector("VarList", allocator, FieldType.nullable(Types .MinorType.VARCHAR.getType()), null); ArrowBuf tempBuf = allocator.buffer(bytes.length)) { @@ -63,15 +65,15 @@ public void testVarCharListWithNulls() { writer.setPosition(2); writer.startList(); - bytes = "b".getBytes(); + bytes = "b".getBytes(StandardCharsets.UTF_8); tempBuf.setBytes(0, bytes); writer.writeVarChar(0, bytes.length, tempBuf); writer.endList(); writer.setValueCount(2); - Assert.assertTrue(vector.getValueCount() == 2); - Assert.assertTrue(vector.getDataVector().getValueCount() == 2); + Assert.assertEquals(2, vector.getValueCount()); + Assert.assertEquals(2, vector.getDataVector().getValueCount()); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java index dfc75ec8e34..b96f6ab6afe 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java @@ -143,7 +143,7 @@ public void testFixedWidthVectorAllocation() { totalCapacity = vec2.getValidityBuffer().capacity() + vec2.getDataBuffer().capacity(); // the total capacity must be a power of two - assertEquals(totalCapacity & (totalCapacity - 1), 0); + assertEquals(0, totalCapacity & (totalCapacity - 1)); } } @@ -163,7 +163,7 @@ public void testVariableWidthVectorAllocation() { totalCapacity = vec2.getValidityBuffer().capacity() + vec2.getOffsetBuffer().capacity(); // the total capacity must be a power of two - assertEquals(totalCapacity & (totalCapacity - 1), 0); + assertEquals(0, totalCapacity & (totalCapacity - 1)); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java index 7d5701ddb76..9043bd4f8f2 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java @@ -324,12 +324,12 @@ public void testVariableRepeatedClearAndSet() throws Exception { vector.allocateNewSafe(); // Initial allocation vector.clear(); // clear vector. - vector.setSafe(0, "hello world".getBytes()); + vector.setSafe(0, "hello world".getBytes(StandardCharsets.UTF_8)); int savedValueCapacity = vector.getValueCapacity(); for (int i = 0; i < 1024; ++i) { vector.clear(); // clear vector. - vector.setSafe(0, "hello world".getBytes()); + vector.setSafe(0, "hello world".getBytes(StandardCharsets.UTF_8)); } // should be deterministic, and not cause a run-away increase in capacity. diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java index ce3fb2cdf0e..207962eb45b 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java @@ -61,7 +61,7 @@ public void testResetRowCount() { VectorSchemaRoot vsr = VectorSchemaRoot.of(vec1, vec2); vsr.allocateNew(); - assertEquals(vsr.getRowCount(), 0); + assertEquals(0, vsr.getRowCount()); for (int i = 0; i < size; i++) { vec1.setSafe(i, i % 2); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java index e03ce0c056b..19f0ea9d4e3 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; @@ -128,9 +129,7 @@ public void simpleNestedTypes() { @Test public void transferPairSchemaChange() { SchemaChangeCallBack callBack1 = new SchemaChangeCallBack(); - SchemaChangeCallBack callBack2 = new SchemaChangeCallBack(); try (NonNullableStructVector parent = populateStructVector(callBack1)) { - TransferPair tp = parent.getTransferPair("newVector", allocator, callBack2); ComplexWriter writer = new ComplexWriterImpl("newWriter", parent); StructWriter rootWriter = writer.rootAsStruct(); @@ -818,7 +817,7 @@ public void promotableWriter() { for (int i = 100; i < 200; i++) { VarCharWriter varCharWriter = rootWriter.varChar("a"); varCharWriter.setPosition(i); - byte[] bytes = Integer.toString(i).getBytes(); + byte[] bytes = Integer.toString(i).getBytes(StandardCharsets.UTF_8); ArrowBuf tempBuf = allocator.buffer(bytes.length); tempBuf.setBytes(0, bytes); varCharWriter.writeVarChar(0, bytes.length, tempBuf); @@ -1719,21 +1718,23 @@ public void structWriterVarBinaryHelpers() { StructWriter rootWriter = writer.rootAsStruct(); rootWriter.start(); rootWriter.setPosition(0); - rootWriter.varBinary("c").writeVarBinary("row1".getBytes()); + rootWriter.varBinary("c").writeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); rootWriter.setPosition(1); - rootWriter.varBinary("c").writeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + rootWriter.varBinary("c").writeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); rootWriter.setPosition(2); - rootWriter.varBinary("c").writeVarBinary(ByteBuffer.wrap("row3".getBytes())); + rootWriter.varBinary("c").writeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); rootWriter.setPosition(3); - rootWriter.varBinary("c").writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + rootWriter.varBinary("c").writeVarBinary(ByteBuffer.wrap( + "row4".getBytes(StandardCharsets.UTF_8)), 0, "row4".getBytes(StandardCharsets.UTF_8).length); rootWriter.end(); VarBinaryVector uv = parent.getChild("root", StructVector.class).getChild("c", VarBinaryVector.class); - assertEquals("row1", new String(uv.get(0))); - assertEquals("row2", new String(uv.get(1))); - assertEquals("row3", new String(uv.get(2))); - assertEquals("row4", new String(uv.get(3))); + assertEquals("row1", new String(uv.get(0), StandardCharsets.UTF_8)); + assertEquals("row2", new String(uv.get(1), StandardCharsets.UTF_8)); + assertEquals("row3", new String(uv.get(2), StandardCharsets.UTF_8)); + assertEquals("row4", new String(uv.get(3), StandardCharsets.UTF_8)); } } @@ -1744,23 +1745,24 @@ public void structWriterLargeVarBinaryHelpers() { StructWriter rootWriter = writer.rootAsStruct(); rootWriter.start(); rootWriter.setPosition(0); - rootWriter.largeVarBinary("c").writeLargeVarBinary("row1".getBytes()); + rootWriter.largeVarBinary("c").writeLargeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); rootWriter.setPosition(1); - rootWriter.largeVarBinary("c").writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + rootWriter.largeVarBinary("c").writeLargeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); rootWriter.setPosition(2); - rootWriter.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes())); + rootWriter.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); rootWriter.setPosition(3); - rootWriter.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, - "row4".getBytes().length); + rootWriter.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap( + "row4".getBytes(StandardCharsets.UTF_8)), 0, "row4".getBytes(StandardCharsets.UTF_8).length); rootWriter.end(); LargeVarBinaryVector uv = parent.getChild("root", StructVector.class).getChild("c", LargeVarBinaryVector.class); - assertEquals("row1", new String(uv.get(0))); - assertEquals("row2", new String(uv.get(1))); - assertEquals("row3", new String(uv.get(2))); - assertEquals("row4", new String(uv.get(3))); + assertEquals("row1", new String(uv.get(0), StandardCharsets.UTF_8)); + assertEquals("row2", new String(uv.get(1), StandardCharsets.UTF_8)); + assertEquals("row3", new String(uv.get(2), StandardCharsets.UTF_8)); + assertEquals("row4", new String(uv.get(3), StandardCharsets.UTF_8)); } } @@ -1800,16 +1802,18 @@ public void listVarBinaryHelpers() { listVector.allocateNew(); UnionListWriter listWriter = new UnionListWriter(listVector); listWriter.startList(); - listWriter.writeVarBinary("row1".getBytes()); - listWriter.writeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); - listWriter.writeVarBinary(ByteBuffer.wrap("row3".getBytes())); - listWriter.writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + listWriter.writeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); + listWriter.writeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); + listWriter.writeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); + listWriter.writeVarBinary(ByteBuffer.wrap( + "row4".getBytes(StandardCharsets.UTF_8)), 0, "row4".getBytes(StandardCharsets.UTF_8).length); listWriter.endList(); listWriter.setValueCount(1); - assertEquals("row1", new String((byte[]) listVector.getObject(0).get(0))); - assertEquals("row2", new String((byte[]) listVector.getObject(0).get(1))); - assertEquals("row3", new String((byte[]) listVector.getObject(0).get(2))); - assertEquals("row4", new String((byte[]) listVector.getObject(0).get(3))); + assertEquals("row1", new String((byte[]) listVector.getObject(0).get(0), StandardCharsets.UTF_8)); + assertEquals("row2", new String((byte[]) listVector.getObject(0).get(1), StandardCharsets.UTF_8)); + assertEquals("row3", new String((byte[]) listVector.getObject(0).get(2), StandardCharsets.UTF_8)); + assertEquals("row4", new String((byte[]) listVector.getObject(0).get(3), StandardCharsets.UTF_8)); } } @@ -1819,16 +1823,18 @@ public void listLargeVarBinaryHelpers() { listVector.allocateNew(); UnionListWriter listWriter = new UnionListWriter(listVector); listWriter.startList(); - listWriter.writeLargeVarBinary("row1".getBytes()); - listWriter.writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); - listWriter.writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes())); - listWriter.writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + listWriter.writeLargeVarBinary("row1".getBytes(StandardCharsets.UTF_8)); + listWriter.writeLargeVarBinary("row2".getBytes(StandardCharsets.UTF_8), 0, + "row2".getBytes(StandardCharsets.UTF_8).length); + listWriter.writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes(StandardCharsets.UTF_8))); + listWriter.writeLargeVarBinary(ByteBuffer.wrap( + "row4".getBytes(StandardCharsets.UTF_8)), 0, "row4".getBytes(StandardCharsets.UTF_8).length); listWriter.endList(); listWriter.setValueCount(1); - assertEquals("row1", new String((byte[]) listVector.getObject(0).get(0))); - assertEquals("row2", new String((byte[]) listVector.getObject(0).get(1))); - assertEquals("row3", new String((byte[]) listVector.getObject(0).get(2))); - assertEquals("row4", new String((byte[]) listVector.getObject(0).get(3))); + assertEquals("row1", new String((byte[]) listVector.getObject(0).get(0), StandardCharsets.UTF_8)); + assertEquals("row2", new String((byte[]) listVector.getObject(0).get(1), StandardCharsets.UTF_8)); + assertEquals("row3", new String((byte[]) listVector.getObject(0).get(2), StandardCharsets.UTF_8)); + assertEquals("row4", new String((byte[]) listVector.getObject(0).get(3), StandardCharsets.UTF_8)); } } @@ -1847,35 +1853,39 @@ public void unionWithVarCharAndBinaryHelpers() throws Exception { unionWriter.setPosition(3); unionWriter.writeLargeVarChar(new Text("row4")); unionWriter.setPosition(4); - unionWriter.writeVarBinary("row5".getBytes()); + unionWriter.writeVarBinary("row5".getBytes(StandardCharsets.UTF_8)); unionWriter.setPosition(5); - unionWriter.writeVarBinary("row6".getBytes(), 0, "row6".getBytes().length); + unionWriter.writeVarBinary("row6".getBytes(StandardCharsets.UTF_8), 0, + "row6".getBytes(StandardCharsets.UTF_8).length); unionWriter.setPosition(6); - unionWriter.writeVarBinary(ByteBuffer.wrap("row7".getBytes())); + unionWriter.writeVarBinary(ByteBuffer.wrap("row7".getBytes(StandardCharsets.UTF_8))); unionWriter.setPosition(7); - unionWriter.writeVarBinary(ByteBuffer.wrap("row8".getBytes()), 0, "row8".getBytes().length); + unionWriter.writeVarBinary(ByteBuffer.wrap("row8".getBytes(StandardCharsets.UTF_8)), 0, + "row8".getBytes(StandardCharsets.UTF_8).length); unionWriter.setPosition(8); - unionWriter.writeLargeVarBinary("row9".getBytes()); + unionWriter.writeLargeVarBinary("row9".getBytes(StandardCharsets.UTF_8)); unionWriter.setPosition(9); - unionWriter.writeLargeVarBinary("row10".getBytes(), 0, "row10".getBytes().length); + unionWriter.writeLargeVarBinary("row10".getBytes(StandardCharsets.UTF_8), 0, + "row10".getBytes(StandardCharsets.UTF_8).length); unionWriter.setPosition(10); - unionWriter.writeLargeVarBinary(ByteBuffer.wrap("row11".getBytes())); + unionWriter.writeLargeVarBinary(ByteBuffer.wrap("row11".getBytes(StandardCharsets.UTF_8))); unionWriter.setPosition(11); - unionWriter.writeLargeVarBinary(ByteBuffer.wrap("row12".getBytes()), 0, "row12".getBytes().length); + unionWriter.writeLargeVarBinary(ByteBuffer.wrap( + "row12".getBytes(StandardCharsets.UTF_8)), 0, "row12".getBytes(StandardCharsets.UTF_8).length); unionWriter.end(); - assertEquals("row1", new String(vector.getVarCharVector().get(0))); - assertEquals("row2", new String(vector.getVarCharVector().get(1))); - assertEquals("row3", new String(vector.getLargeVarCharVector().get(2))); - assertEquals("row4", new String(vector.getLargeVarCharVector().get(3))); - assertEquals("row5", new String(vector.getVarBinaryVector().get(4))); - assertEquals("row6", new String(vector.getVarBinaryVector().get(5))); - assertEquals("row7", new String(vector.getVarBinaryVector().get(6))); - assertEquals("row8", new String(vector.getVarBinaryVector().get(7))); - assertEquals("row9", new String(vector.getLargeVarBinaryVector().get(8))); - assertEquals("row10", new String(vector.getLargeVarBinaryVector().get(9))); - assertEquals("row11", new String(vector.getLargeVarBinaryVector().get(10))); - assertEquals("row12", new String(vector.getLargeVarBinaryVector().get(11))); + assertEquals("row1", new String(vector.getVarCharVector().get(0), StandardCharsets.UTF_8)); + assertEquals("row2", new String(vector.getVarCharVector().get(1), StandardCharsets.UTF_8)); + assertEquals("row3", new String(vector.getLargeVarCharVector().get(2), StandardCharsets.UTF_8)); + assertEquals("row4", new String(vector.getLargeVarCharVector().get(3), StandardCharsets.UTF_8)); + assertEquals("row5", new String(vector.getVarBinaryVector().get(4), StandardCharsets.UTF_8)); + assertEquals("row6", new String(vector.getVarBinaryVector().get(5), StandardCharsets.UTF_8)); + assertEquals("row7", new String(vector.getVarBinaryVector().get(6), StandardCharsets.UTF_8)); + assertEquals("row8", new String(vector.getVarBinaryVector().get(7), StandardCharsets.UTF_8)); + assertEquals("row9", new String(vector.getLargeVarBinaryVector().get(8), StandardCharsets.UTF_8)); + assertEquals("row10", new String(vector.getLargeVarBinaryVector().get(9), StandardCharsets.UTF_8)); + assertEquals("row11", new String(vector.getLargeVarBinaryVector().get(10), StandardCharsets.UTF_8)); + assertEquals("row12", new String(vector.getLargeVarBinaryVector().get(11), StandardCharsets.UTF_8)); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java index 8663c0c4999..de9187edb66 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java @@ -694,19 +694,19 @@ protected void writeBatchData(ArrowWriter writer, IntVector vector, VectorSchema protected void validateBatchData(ArrowReader reader, IntVector vector) throws IOException { reader.loadNextBatch(); - assertEquals(vector.getValueCount(), 5); + assertEquals(5, vector.getValueCount()); assertTrue(vector.isNull(0)); - assertEquals(vector.get(1), 1); - assertEquals(vector.get(2), 2); + assertEquals(1, vector.get(1)); + assertEquals(2, vector.get(2)); assertTrue(vector.isNull(3)); - assertEquals(vector.get(4), 1); + assertEquals(1, vector.get(4)); reader.loadNextBatch(); - assertEquals(vector.getValueCount(), 3); + assertEquals(3, vector.getValueCount()); assertTrue(vector.isNull(0)); - assertEquals(vector.get(1), 1); - assertEquals(vector.get(2), 2); + assertEquals(1, vector.get(1)); + assertEquals(2, vector.get(2)); } protected VectorSchemaRoot writeMapData(BufferAllocator bufferAllocator) { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java index 0aa49d9daa0..bd5bd4feabb 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java @@ -476,7 +476,7 @@ public void testRoundtripEmptyVector() throws Exception { assertEquals(schema, readSchema); try (final VectorSchemaRoot data = reader.read()) { assertNotNull(data); - assertEquals(data.getRowCount(), 0); + assertEquals(0, data.getRowCount()); } assertNull(reader.read()); } @@ -496,7 +496,7 @@ public void testRoundtripEmptyVector() throws Exception { assertEquals(schema, readSchema); try (final VectorSchemaRoot data = reader.read()) { assertNotNull(data); - assertEquals(data.getRowCount(), 0); + assertEquals(0, data.getRowCount()); } assertNull(reader.read()); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java b/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java index eb50e866b19..3e6a096104d 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java @@ -650,8 +650,8 @@ void getVarChar() { c.setPosition(1); assertEquals(c.getVarCharObj(1), "two"); assertEquals(c.getVarCharObj(1), c.getVarCharObj(VARCHAR_VECTOR_NAME_1)); - assertArrayEquals("two".getBytes(), c.getVarChar(VARCHAR_VECTOR_NAME_1)); - assertArrayEquals("two".getBytes(), c.getVarChar(1)); + assertArrayEquals("two".getBytes(StandardCharsets.UTF_8), c.getVarChar(VARCHAR_VECTOR_NAME_1)); + assertArrayEquals("two".getBytes(StandardCharsets.UTF_8), c.getVarChar(1)); } } @@ -661,7 +661,7 @@ void getVarBinary() { try (Table t = new Table(vectorList)) { Row c = t.immutableRow(); c.setPosition(1); - assertArrayEquals(c.getVarBinary(1), "two".getBytes()); + assertArrayEquals(c.getVarBinary(1), "two".getBytes(StandardCharsets.UTF_8)); assertArrayEquals(c.getVarBinary(1), c.getVarBinary(VARBINARY_VECTOR_NAME_1)); } } @@ -672,7 +672,7 @@ void getLargeVarBinary() { try (Table t = new Table(vectorList)) { Row c = t.immutableRow(); c.setPosition(1); - assertArrayEquals(c.getLargeVarBinary(1), "two".getBytes()); + assertArrayEquals(c.getLargeVarBinary(1), "two".getBytes(StandardCharsets.UTF_8)); assertArrayEquals(c.getLargeVarBinary(1), c.getLargeVarBinary(VARBINARY_VECTOR_NAME_1)); } } @@ -685,8 +685,8 @@ void getLargeVarChar() { c.setPosition(1); assertEquals(c.getLargeVarCharObj(1), "two"); assertEquals(c.getLargeVarCharObj(1), c.getLargeVarCharObj(VARCHAR_VECTOR_NAME_1)); - assertArrayEquals("two".getBytes(), c.getLargeVarChar(VARCHAR_VECTOR_NAME_1)); - assertArrayEquals("two".getBytes(), c.getLargeVarChar(1)); + assertArrayEquals("two".getBytes(StandardCharsets.UTF_8), c.getLargeVarChar(VARCHAR_VECTOR_NAME_1)); + assertArrayEquals("two".getBytes(StandardCharsets.UTF_8), c.getLargeVarChar(1)); } } @@ -696,7 +696,7 @@ void getFixedBinary() { try (Table t = new Table(vectorList)) { Row c = t.immutableRow(); c.setPosition(1); - assertArrayEquals(c.getFixedSizeBinary(1), "two".getBytes()); + assertArrayEquals(c.getFixedSizeBinary(1), "two".getBytes(StandardCharsets.UTF_8)); assertArrayEquals(c.getFixedSizeBinary(1), c.getFixedSizeBinary(FIXEDBINARY_VECTOR_NAME_1)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java index 084350410a4..872b2f3934b 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java @@ -221,7 +221,7 @@ public void roundtripLocation() throws IOException { final ExtensionTypeVector deserialized = (ExtensionTypeVector) readerRoot.getFieldVectors().get(0); Assert.assertTrue(deserialized instanceof LocationVector); - Assert.assertEquals(deserialized.getName(), "location"); + Assert.assertEquals("location", deserialized.getName()); StructVector deserStruct = (StructVector) deserialized.getUnderlyingVector(); Assert.assertNotNull(deserStruct.getChild("Latitude")); Assert.assertNotNull(deserStruct.getChild("Longitude")); @@ -273,7 +273,7 @@ public void testVectorCompare() { // Test out vector appender VectorBatchAppender.batchAppend(a1, a2, bb); - assertEquals(a1.getValueCount(), 6); + assertEquals(6, a1.getValueCount()); validateVisitor.visit(a1, null); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java index 419872225e1..1c8281c8598 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java @@ -20,6 +20,8 @@ import static junit.framework.TestCase.assertNull; import static org.junit.Assert.assertEquals; +import java.nio.charset.StandardCharsets; + import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.memory.util.ArrowBufPointer; @@ -98,7 +100,7 @@ public void testIterateVarCharVector() { if (i == 0) { strVector.setNull(i); } else { - strVector.set(i, String.valueOf(i).getBytes()); + strVector.set(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } } @@ -125,7 +127,7 @@ public void testIterateVarCharVector() { assertEquals(expected.length(), pt.getLength()); pt.getBuf().getBytes(pt.getOffset(), actual); - assertEquals(expected, new String(actual)); + assertEquals(expected, new String(actual, StandardCharsets.UTF_8)); } index += 1; } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java index ab36ea2fd21..93e75359475 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java @@ -437,8 +437,6 @@ public void testAppendStructVector() { delta.accept(appender, null); assertEquals(length1 + length2, target.getValueCount()); - IntVector child1 = (IntVector) target.getVectorById(0); - VarCharVector child2 = (VarCharVector) target.getVectorById(1); try (IntVector expected1 = new IntVector("expected1", allocator); VarCharVector expected2 = new VarCharVector("expected2", allocator)) { From 7175c9d427289daf267b5d78fd03663fead57f78 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Thu, 18 Jan 2024 08:36:20 +0530 Subject: [PATCH 18/23] fix: address reviews v1 (changing static utf_8 import) --- .../TestHashTableDictionaryEncoder.java | 27 +++++----- .../TestLinearDictionaryEncoder.java | 28 +++++----- .../TestSearchDictionaryEncoder.java | 28 +++++----- .../sort/TestCompositeVectorComparator.java | 6 +-- .../arrow/algorithm/sort/TestSortingUtil.java | 4 +- .../sort/TestStableVectorComparator.java | 52 +++++++++---------- .../sort/TestVariableWidthSorting.java | 8 +-- .../arrow/flight/FlightCallHeaders.java | 13 ++--- .../arrow/flight/TestBasicOperation.java | 11 ++-- .../arrow/flight/sql/SqlInfoBuilder.java | 5 +- 10 files changed, 94 insertions(+), 88 deletions(-) diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java index f33cfc21fab..60efbf58beb 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestHashTableDictionaryEncoder.java @@ -17,12 +17,12 @@ package org.apache.arrow.algorithm.dictionary; -import static java.nio.charset.StandardCharsets.UTF_8; import static junit.framework.TestCase.assertTrue; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; @@ -49,9 +49,9 @@ public class TestHashTableDictionaryEncoder { private BufferAllocator allocator; - byte[] zero = "000".getBytes(UTF_8); - byte[] one = "111".getBytes(UTF_8); - byte[] two = "222".getBytes(UTF_8); + byte[] zero = "000".getBytes(StandardCharsets.UTF_8); + byte[] one = "111".getBytes(StandardCharsets.UTF_8); + byte[] two = "222".getBytes(StandardCharsets.UTF_8); byte[][] data = new byte[][]{zero, one, two}; @@ -76,7 +76,7 @@ public void testEncodeAndDecode() { dictionary.allocateNew(); for (int i = 0; i < DICTIONARY_LENGTH; i++) { // encode "i" as i - dictionary.setSafe(i, String.valueOf(i).getBytes(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -84,7 +84,7 @@ public void testEncodeAndDecode() { 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(UTF_8)); + rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8)); } rawVector.setValueCount(VECTOR_LENGTH); @@ -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(UTF_8)); + assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8)); } // perform decoding @@ -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(UTF_8), decodedVector.get(i)); + assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8), + decodedVector.get(i)); } } } @@ -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(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -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(UTF_8)); + rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8)); } } rawVector.setValueCount(VECTOR_LENGTH); @@ -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(UTF_8)); + assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8)); } } @@ -168,7 +169,7 @@ public void testEncodeAndDecodeWithNull() { if (i % 10 == 0) { assertTrue(decodedVector.isNull(i)); } else { - assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(UTF_8), + assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8), decodedVector.get(i)); } } @@ -186,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(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java index 77c939f330c..a76aedffa30 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestLinearDictionaryEncoder.java @@ -17,12 +17,12 @@ package org.apache.arrow.algorithm.dictionary; -import static java.nio.charset.StandardCharsets.UTF_8; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; @@ -50,9 +50,9 @@ public class TestLinearDictionaryEncoder { private BufferAllocator allocator; - byte[] zero = "000".getBytes(UTF_8); - byte[] one = "111".getBytes(UTF_8); - byte[] two = "222".getBytes(UTF_8); + byte[] zero = "000".getBytes(StandardCharsets.UTF_8); + byte[] one = "111".getBytes(StandardCharsets.UTF_8); + byte[] two = "222".getBytes(StandardCharsets.UTF_8); byte[][] data = new byte[][]{zero, one, two}; @@ -77,7 +77,7 @@ public void testEncodeAndDecode() { dictionary.allocateNew(); for (int i = 0; i < DICTIONARY_LENGTH; i++) { // encode "i" as i - dictionary.setSafe(i, String.valueOf(i).getBytes(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -85,7 +85,7 @@ public void testEncodeAndDecode() { 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(UTF_8)); + rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8)); } rawVector.setValueCount(VECTOR_LENGTH); @@ -99,7 +99,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(UTF_8)); + assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8)); } // perform decoding @@ -109,7 +109,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(UTF_8), decodedVector.get(i)); + assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8), + decodedVector.get(i)); } } } @@ -127,7 +128,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(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -138,7 +139,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(UTF_8)); + rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8)); } } rawVector.setValueCount(VECTOR_LENGTH); @@ -156,7 +157,7 @@ public void testEncodeAndDecodeWithNull() { if (i % 10 == 0) { assertEquals(0, encodedVector.get(i)); } else { - assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(UTF_8)); + assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8)); } } @@ -170,7 +171,8 @@ public void testEncodeAndDecodeWithNull() { if (i % 10 == 0) { assertTrue(decodedVector.isNull(i)); } else { - assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(UTF_8), decodedVector.get(i)); + assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8), + decodedVector.get(i)); } } } @@ -187,7 +189,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(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java index 2a351b24a67..e01c2e7905b 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/dictionary/TestSearchDictionaryEncoder.java @@ -17,12 +17,12 @@ package org.apache.arrow.algorithm.dictionary; -import static java.nio.charset.StandardCharsets.UTF_8; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; @@ -51,9 +51,9 @@ public class TestSearchDictionaryEncoder { private BufferAllocator allocator; - byte[] zero = "000".getBytes(UTF_8); - byte[] one = "111".getBytes(UTF_8); - byte[] two = "222".getBytes(UTF_8); + byte[] zero = "000".getBytes(StandardCharsets.UTF_8); + byte[] one = "111".getBytes(StandardCharsets.UTF_8); + byte[] two = "222".getBytes(StandardCharsets.UTF_8); byte[][] data = new byte[][]{zero, one, two}; @@ -78,7 +78,7 @@ public void testEncodeAndDecode() { dictionary.allocateNew(); for (int i = 0; i < DICTIONARY_LENGTH; i++) { // encode "i" as i - dictionary.setSafe(i, String.valueOf(i).getBytes(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -86,7 +86,7 @@ public void testEncodeAndDecode() { 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(UTF_8)); + rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8)); } rawVector.setValueCount(VECTOR_LENGTH); @@ -101,7 +101,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(UTF_8)); + assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8)); } // perform decoding @@ -111,7 +111,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(UTF_8), decodedVector.get(i)); + assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8), + decodedVector.get(i)); } } } @@ -129,7 +130,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(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); @@ -140,7 +141,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(UTF_8)); + rawVector.set(i, String.valueOf(val).getBytes(StandardCharsets.UTF_8)); } } rawVector.setValueCount(VECTOR_LENGTH); @@ -159,7 +160,7 @@ public void testEncodeAndDecodeWithNull() { if (i % 10 == 0) { assertEquals(0, encodedVector.get(i)); } else { - assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(UTF_8)); + assertArrayEquals(rawVector.get(i), String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8)); } } @@ -173,7 +174,8 @@ public void testEncodeAndDecodeWithNull() { if (i % 10 == 0) { assertTrue(decodedVector.isNull(i)); } else { - assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(UTF_8), decodedVector.get(i)); + assertArrayEquals(String.valueOf(encodedVector.get(i)).getBytes(StandardCharsets.UTF_8), + decodedVector.get(i)); } } } @@ -190,7 +192,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(UTF_8)); + dictionary.setSafe(i, String.valueOf(i).getBytes(StandardCharsets.UTF_8)); } dictionary.setValueCount(DICTIONARY_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java index f7539e714f1..9624432924b 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestCompositeVectorComparator.java @@ -17,10 +17,10 @@ package org.apache.arrow.algorithm.sort; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.apache.arrow.memory.BufferAllocator; @@ -69,9 +69,9 @@ public void testCompareVectorSchemaRoot() { for (int i = 0; i < vectorLength; i++) { intVec1.set(i, i); - strVec1.set(i, ("a" + i).getBytes(UTF_8)); + strVec1.set(i, ("a" + i).getBytes(StandardCharsets.UTF_8)); intVec2.set(i, i); - strVec2.set(i, "a5".getBytes(UTF_8)); + strVec2.set(i, "a5".getBytes(StandardCharsets.UTF_8)); } VectorValueComparator innerComparator1 = diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java index c6c17f1c845..e22b22d4e67 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestSortingUtil.java @@ -17,10 +17,10 @@ package org.apache.arrow.algorithm.sort; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.Array; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; import java.util.function.BiConsumer; @@ -123,7 +123,7 @@ static String generateRandomString(int length) { str[i] = (byte) (r % (upper - lower + 1) + lower); } - return new String(str, UTF_8); + return new String(str, StandardCharsets.UTF_8); } /** diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java index 0bf1cc6a702..f2de5d23fce 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestStableVectorComparator.java @@ -17,10 +17,10 @@ package org.apache.arrow.algorithm.sort; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.Objects; import org.apache.arrow.memory.BufferAllocator; @@ -55,11 +55,11 @@ public void testCompare() { vec.setValueCount(10); // fill data to sort - vec.set(0, "ba".getBytes(UTF_8)); - vec.set(1, "abc".getBytes(UTF_8)); - vec.set(2, "aa".getBytes(UTF_8)); - vec.set(3, "abc".getBytes(UTF_8)); - vec.set(4, "a".getBytes(UTF_8)); + vec.set(0, "ba".getBytes(StandardCharsets.UTF_8)); + vec.set(1, "abc".getBytes(StandardCharsets.UTF_8)); + vec.set(2, "aa".getBytes(StandardCharsets.UTF_8)); + vec.set(3, "abc".getBytes(StandardCharsets.UTF_8)); + vec.set(4, "a".getBytes(StandardCharsets.UTF_8)); VectorValueComparator comparator = new TestVarCharSorter(); VectorValueComparator stableComparator = new StableVectorComparator<>(comparator); @@ -81,16 +81,16 @@ public void testStableSortString() { vec.setValueCount(10); // fill data to sort - vec.set(0, "a".getBytes(UTF_8)); - vec.set(1, "abc".getBytes(UTF_8)); - vec.set(2, "aa".getBytes(UTF_8)); - vec.set(3, "a1".getBytes(UTF_8)); - vec.set(4, "abcdefg".getBytes(UTF_8)); - vec.set(5, "accc".getBytes(UTF_8)); - vec.set(6, "afds".getBytes(UTF_8)); - vec.set(7, "0".getBytes(UTF_8)); - vec.set(8, "01".getBytes(UTF_8)); - vec.set(9, "0c".getBytes(UTF_8)); + vec.set(0, "a".getBytes(StandardCharsets.UTF_8)); + vec.set(1, "abc".getBytes(StandardCharsets.UTF_8)); + vec.set(2, "aa".getBytes(StandardCharsets.UTF_8)); + vec.set(3, "a1".getBytes(StandardCharsets.UTF_8)); + vec.set(4, "abcdefg".getBytes(StandardCharsets.UTF_8)); + vec.set(5, "accc".getBytes(StandardCharsets.UTF_8)); + vec.set(6, "afds".getBytes(StandardCharsets.UTF_8)); + vec.set(7, "0".getBytes(StandardCharsets.UTF_8)); + vec.set(8, "01".getBytes(StandardCharsets.UTF_8)); + vec.set(9, "0c".getBytes(StandardCharsets.UTF_8)); // sort the vector VariableWidthOutOfPlaceVectorSorter sorter = new VariableWidthOutOfPlaceVectorSorter(); @@ -107,16 +107,16 @@ public void testStableSortString() { // verify results // the results are stable - assertEquals("0", new String(Objects.requireNonNull(sortedVec.get(0)), UTF_8)); - assertEquals("01", new String(Objects.requireNonNull(sortedVec.get(1)), UTF_8)); - assertEquals("0c", new String(Objects.requireNonNull(sortedVec.get(2)), UTF_8)); - assertEquals("a", new String(Objects.requireNonNull(sortedVec.get(3)), UTF_8)); - assertEquals("abc", new String(Objects.requireNonNull(sortedVec.get(4)), UTF_8)); - assertEquals("aa", new String(Objects.requireNonNull(sortedVec.get(5)), UTF_8)); - assertEquals("a1", new String(Objects.requireNonNull(sortedVec.get(6)), UTF_8)); - assertEquals("abcdefg", new String(Objects.requireNonNull(sortedVec.get(7)), UTF_8)); - assertEquals("accc", new String(Objects.requireNonNull(sortedVec.get(8)), UTF_8)); - assertEquals("afds", new String(Objects.requireNonNull(sortedVec.get(9)), UTF_8)); + assertEquals("0", new String(Objects.requireNonNull(sortedVec.get(0)), StandardCharsets.UTF_8)); + assertEquals("01", new String(Objects.requireNonNull(sortedVec.get(1)), StandardCharsets.UTF_8)); + assertEquals("0c", new String(Objects.requireNonNull(sortedVec.get(2)), StandardCharsets.UTF_8)); + assertEquals("a", new String(Objects.requireNonNull(sortedVec.get(3)), StandardCharsets.UTF_8)); + assertEquals("abc", new String(Objects.requireNonNull(sortedVec.get(4)), StandardCharsets.UTF_8)); + assertEquals("aa", new String(Objects.requireNonNull(sortedVec.get(5)), StandardCharsets.UTF_8)); + assertEquals("a1", new String(Objects.requireNonNull(sortedVec.get(6)), StandardCharsets.UTF_8)); + assertEquals("abcdefg", new String(Objects.requireNonNull(sortedVec.get(7)), StandardCharsets.UTF_8)); + assertEquals("accc", new String(Objects.requireNonNull(sortedVec.get(8)), StandardCharsets.UTF_8)); + assertEquals("afds", new String(Objects.requireNonNull(sortedVec.get(9)), StandardCharsets.UTF_8)); } } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java index 46f92dbb10b..7951c39d550 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java @@ -17,11 +17,11 @@ package org.apache.arrow.algorithm.sort; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -131,7 +131,7 @@ public static void verifyResults(V vector, String[] expe if (expected[i] == null) { assertTrue(vector.isNull(i)); } else { - assertArrayEquals(((Text) vector.getObject(i)).getBytes(), expected[i].getBytes(UTF_8)); + assertArrayEquals(((Text) vector.getObject(i)).getBytes(), expected[i].getBytes(StandardCharsets.UTF_8)); } } } @@ -152,8 +152,8 @@ public int compare(String str1, String str2) { return str1 == null ? -1 : 1; } - byte[] bytes1 = str1.getBytes(UTF_8); - byte[] bytes2 = str2.getBytes(UTF_8); + byte[] bytes1 = str1.getBytes(StandardCharsets.UTF_8); + byte[] bytes2 = str2.getBytes(StandardCharsets.UTF_8); for (int i = 0; i < bytes1.length && i < bytes2.length; i++) { if (bytes1[i] != bytes2[i]) { diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java index 6b730fb841d..93b89e77550 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java @@ -17,8 +17,7 @@ package org.apache.arrow.flight; -import static java.nio.charset.StandardCharsets.UTF_8; - +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; @@ -48,7 +47,7 @@ public String get(String key) { } if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { - return new String((byte[]) Iterables.get(values, 0), UTF_8); + return new String((byte[]) Iterables.get(values, 0), StandardCharsets.UTF_8); } return (String) Iterables.get(values, 0); @@ -65,13 +64,14 @@ public byte[] getByte(String key) { return (byte[]) Iterables.get(values, 0); } - return ((String) Iterables.get(values, 0)).getBytes(UTF_8); + return ((String) Iterables.get(values, 0)).getBytes(StandardCharsets.UTF_8); } @Override public Iterable getAll(String key) { if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { - return this.keysAndValues.get(key).stream().map(o -> new String((byte[]) o, UTF_8)).collect(Collectors.toList()); + return this.keysAndValues.get(key).stream().map(o -> new String((byte[]) o, StandardCharsets.UTF_8)) + .collect(Collectors.toList()); } return (Collection) (Collection) this.keysAndValues.get(key); } @@ -81,7 +81,8 @@ public Iterable getAllByte(String key) { if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) { return (Collection) (Collection) this.keysAndValues.get(key); } - return this.keysAndValues.get(key).stream().map(o -> ((String) o).getBytes(UTF_8)).collect(Collectors.toList()); + return this.keysAndValues.get(key).stream().map(o -> ((String) o).getBytes(StandardCharsets.UTF_8)) + .collect(Collectors.toList()); } @Override diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java index 0335c73f234..ae520ee9b99 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java @@ -17,7 +17,7 @@ package org.apache.arrow.flight; -import static java.nio.charset.StandardCharsets.UTF_8; + import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST; import static org.apache.arrow.flight.Location.forGrpcInsecure; @@ -29,6 +29,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.channels.Channels; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -114,11 +115,11 @@ public void roundTripInfo() throws Exception { Field.nullable("b", new ArrowType.FixedSizeBinary(32)) ), metadata); final FlightInfo info1 = FlightInfo.builder(schema, FlightDescriptor.path(), Collections.emptyList()) - .setAppMetadata("foo".getBytes(UTF_8)).build(); + .setAppMetadata("foo".getBytes(StandardCharsets.UTF_8)).build(); final FlightInfo info2 = new FlightInfo(schema, FlightDescriptor.command(new byte[2]), Collections.singletonList( FlightEndpoint.builder(new Ticket(new byte[10]), Location.forGrpcDomainSocket("/tmp/test.sock")) - .setAppMetadata("bar".getBytes(UTF_8)).build() + .setAppMetadata("bar".getBytes(StandardCharsets.UTF_8)).build() ), 200, 500); final FlightInfo info3 = new FlightInfo(schema, FlightDescriptor.path("a", "b"), Arrays.asList(new FlightEndpoint( @@ -150,7 +151,7 @@ public void roundTripInfo() throws Exception { @Test public void roundTripDescriptor() throws Exception { - final FlightDescriptor cmd = FlightDescriptor.command("test command".getBytes(UTF_8)); + final FlightDescriptor cmd = FlightDescriptor.command("test command".getBytes(StandardCharsets.UTF_8)); Assertions.assertEquals(cmd, FlightDescriptor.deserialize(cmd.serialize())); final FlightDescriptor path = FlightDescriptor.path("foo", "bar", "test.arrow"); Assertions.assertEquals(path, FlightDescriptor.deserialize(path.serialize())); @@ -461,7 +462,7 @@ public void testGrpcTlsLocation() throws Exception { * An example FlightProducer for test purposes. */ public static class Producer implements FlightProducer, AutoCloseable { - static final byte[] TICKET_LARGE_BATCH = "large-batch".getBytes(UTF_8); + static final byte[] TICKET_LARGE_BATCH = "large-batch".getBytes(StandardCharsets.UTF_8); private final BufferAllocator allocator; diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java index 251a709f639..338a60e2ae6 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java @@ -17,7 +17,6 @@ package org.apache.arrow.flight.sql; -import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.IntStream.range; import static org.apache.arrow.flight.FlightProducer.ServerStreamListener; import static org.apache.arrow.flight.sql.impl.FlightSql.SqlSupportedTransaction; @@ -81,7 +80,7 @@ public class SqlInfoBuilder { * @return a new {@link NullableVarCharHolder} with the provided input data {@code string}. */ public static NullableVarCharHolder getHolderForUtf8(final String string, final ArrowBuf buf) { - final byte[] bytes = string.getBytes(UTF_8); + final byte[] bytes = string.getBytes(StandardCharsets.UTF_8); buf.setBytes(0, bytes); final NullableVarCharHolder holder = new NullableVarCharHolder(); holder.buffer = buf; @@ -1051,7 +1050,7 @@ private void setDataVarCharListField(final VectorSchemaRoot root, final int inde final int length = values.length; range(0, length) .forEach(i -> onCreateArrowBuf(buf -> { - final byte[] bytes = values[i].getBytes(UTF_8); + final byte[] bytes = values[i].getBytes(StandardCharsets.UTF_8); buf.setBytes(0, bytes); writer.writeVarChar(0, bytes.length, buf); })); From 220c6d463d2255e55f79d45d9a808ba0dc89354c Mon Sep 17 00:00:00 2001 From: vibhatha Date: Thu, 18 Jan 2024 14:25:10 +0530 Subject: [PATCH 19/23] fix: address reviews v2 --- java/flight/flight-core/pom.xml | 1 + .../arrow/flight/grpc/AddWritableBuffer.java | 2 +- .../arrow/flight/grpc/GetReadableBuffer.java | 2 +- .../arrow/flight/TestServerMiddleware.java | 10 ++++----- .../driver/jdbc/ArrowFlightJdbcDriver.java | 18 +++++++-------- .../ArrowFlightConnectionConfigImpl.java | 3 +-- .../arrow/driver/jdbc/utils/UrlParser.java | 7 +++--- .../flight/sql/example/FlightSqlExample.java | 8 +++---- .../apache/arrow/vector/VectorSchemaRoot.java | 1 - .../vector/complex/AbstractStructVector.java | 2 +- .../vector/complex/impl/PromotableWriter.java | 2 +- .../org/apache/arrow/vector/util/Text.java | 4 +--- .../arrow/vector/TestLargeListVector.java | 22 +++++++++---------- 13 files changed, 37 insertions(+), 45 deletions(-) diff --git a/java/flight/flight-core/pom.xml b/java/flight/flight-core/pom.xml index 0346172f610..b8cf6e3000c 100644 --- a/java/flight/flight-core/pom.xml +++ b/java/flight/flight-core/pom.xml @@ -89,6 +89,7 @@ com.google.protobuf protobuf-java-util + 3.23.1 io.grpc diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java index a4cacc71327..4a99ab22842 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/AddWritableBuffer.java @@ -72,7 +72,7 @@ public class AddWritableBuffer { tmpBufChainOut = tmpBufChainOut2; } catch (Exception ex) { - throw new RuntimeException("Failed to initialize AddWritableBuffer, falling back to slow path", ex); + new RuntimeException("Failed to initialize AddWritableBuffer, falling back to slow path", ex).printStackTrace(); } bufConstruct = tmpConstruct; diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java index bd2e780a0ce..82cfd7f39c9 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/GetReadableBuffer.java @@ -51,7 +51,7 @@ public class GetReadableBuffer { tmpField = f; tmpClazz = clazz; } catch (Exception e) { - throw new RuntimeException("Failed to initialize GetReadableBuffer, falling back to slow path", e); + new RuntimeException("Failed to initialize GetReadableBuffer, falling back to slow path", e).printStackTrace(); } READABLE_BUFFER = tmpField; BUFFER_INPUT_STREAM = tmpClazz; diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java index e209f62402c..3bc8f2f90a6 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java @@ -104,7 +104,7 @@ public void doPutUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); + Assertions.assertEquals("test", err.getMessage()); }); } @@ -119,7 +119,7 @@ public void listFlightsUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); + Assertions.assertEquals("test", err.getMessage()); }); } @@ -134,7 +134,7 @@ public void doActionUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); + Assertions.assertEquals("test", err.getMessage()); }); } @@ -149,7 +149,7 @@ public void listActionsUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); + Assertions.assertEquals("test", err.getMessage()); }); } @@ -184,7 +184,7 @@ public void doGetUncaught() { Assertions.assertEquals(FlightStatusCode.OK, status.code()); Assertions.assertNull(status.cause()); Assertions.assertNotNull(err); - Assertions.assertEquals(new RuntimeException("test").getMessage(), err.getMessage()); + Assertions.assertEquals("test", err.getMessage()); }); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java index 9ec560085c7..183e3d5c7b0 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java @@ -27,7 +27,6 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.sql.SQLException; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -44,8 +43,6 @@ import org.apache.calcite.avatica.Meta; import org.apache.calcite.avatica.UnregisteredDriver; -import com.google.common.base.Ascii; -import com.google.common.base.Splitter; /** * JDBC driver for querying data from an Apache Arrow Flight server. @@ -103,6 +100,7 @@ protected String getFactoryClassName(final JdbcVersion jdbcVersion) { } @Override + @SuppressWarnings("StringSplitter") protected DriverVersion createDriverVersion() { if (version == null) { final InputStream flightProperties = this.getClass().getResourceAsStream("/properties/flight.properties"); @@ -115,17 +113,17 @@ protected DriverVersion createDriverVersion() { final String parentName = properties.getProperty("org.apache.arrow.flight.name"); final String parentVersion = properties.getProperty("org.apache.arrow.flight.version"); - final List pVersion = Splitter.on('.').splitToList(parentVersion); + final String[] pVersion = parentVersion.split("\\."); - final int parentMajorVersion = Integer.parseInt(pVersion.get(0)); - final int parentMinorVersion = Integer.parseInt(pVersion.get(1)); + final int parentMajorVersion = Integer.parseInt(pVersion[0]); + final int parentMinorVersion = Integer.parseInt(pVersion[1]); final String childName = properties.getProperty("org.apache.arrow.flight.jdbc-driver.name"); final String childVersion = properties.getProperty("org.apache.arrow.flight.jdbc-driver.version"); - final List cVersion = Splitter.on('.').splitToList(childVersion); + final String[] cVersion = childVersion.split("\\."); - final int childMajorVersion = Integer.parseInt(cVersion.get(0)); - final int childMinorVersion = Integer.parseInt(cVersion.get(1)); + final int childMajorVersion = Integer.parseInt(cVersion[0]); + final int childMinorVersion = Integer.parseInt(cVersion[1]); version = new DriverVersion( childName, @@ -271,7 +269,7 @@ Optional> getUrlsArgs(String url) static Properties lowerCasePropertyKeys(final Properties properties) { final Properties resultProperty = new Properties(); - properties.forEach((k, v) -> resultProperty.put(Ascii.toLowerCase(k.toString()), v)); + properties.forEach((k, v) -> resultProperty.put(k.toString().toLowerCase(), v)); return resultProperty; } } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java index 277e42cb975..e95cf00bc7a 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java @@ -33,7 +33,6 @@ import org.apache.calcite.avatica.ConnectionConfigImpl; import org.apache.calcite.avatica.ConnectionProperty; -import com.google.common.base.Ascii; /** * A {@link ConnectionConfig} for the {@link ArrowFlightConnection}. @@ -236,7 +235,7 @@ public Object get(final Properties properties) { Preconditions.checkNotNull(properties, "Properties cannot be null."); Object value = properties.get(camelName); if (value == null) { - value = properties.get(Ascii.toLowerCase(camelName)); + value = properties.get(camelName.toLowerCase()); } if (required) { if (value == null) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java index ee5a63b8a61..64255e2213a 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java @@ -21,12 +21,10 @@ import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; - -import com.google.common.base.Splitter; - /** * URL Parser for extracting key values from a connection string. */ + public final class UrlParser { private UrlParser() { } @@ -39,10 +37,11 @@ private UrlParser() { * @param url {@link String} * @return {@link Map} */ + @SuppressWarnings("StringSplitter") public static Map parse(String url, String separator) { Map resultMap = new HashMap<>(); if (url != null) { - Iterable keyValues = Splitter.onPattern(separator).split(url); + String[] keyValues = url.split(separator); for (String keyValue : keyValues) { try { diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java index ea00900d665..1d43728b789 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java @@ -141,7 +141,6 @@ import org.apache.commons.pool2.impl.GenericObjectPool; import org.slf4j.Logger; -import com.google.common.base.Splitter; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.RemovalListener; @@ -384,6 +383,7 @@ private static int saveToVectors(final Map ve return saveToVectors(vectorToColumnName, data, emptyToNull, alwaysTrue); } + @SuppressWarnings("StringSplitter") private static int saveToVectors(final Map vectorToColumnName, final ResultSet data, boolean emptyToNull, Predicate resultSetPredicate) @@ -424,11 +424,11 @@ private static int saveToVectors(final Map ve writer.startList(); if (createParamsValues != null) { - List split = Splitter.on(',').splitToList(createParamsValues); + String[] split = createParamsValues.split(","); - range(0, split.size()) + range(0, split.length) .forEach(i -> { - byte[] bytes = split.get(i).getBytes(UTF_8); + byte[] bytes = split[i].getBytes(UTF_8); Preconditions.checkState(bytes.length < 1024, "The amount of bytes is greater than what the ArrowBuf supports"); buf.setBytes(0, bytes); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java b/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java index 510bc1169b5..8768a90c80b 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java @@ -339,7 +339,6 @@ public VectorSchemaRoot slice(int index, int length) { /** * Determine if two VectorSchemaRoots are exactly equal. */ - public boolean equals(VectorSchemaRoot other) { if (other == null) { return false; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java index 1b604eb9082..80efea6cbe3 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/AbstractStructVector.java @@ -57,7 +57,7 @@ public abstract class AbstractStructVector extends AbstractContainerVector { } ConflictPolicy conflictPolicy; try { - conflictPolicy = ConflictPolicy.valueOf(conflictPolicyStr.toUpperCase(Locale.getDefault())); + conflictPolicy = ConflictPolicy.valueOf(conflictPolicyStr.toUpperCase(Locale.ROOT)); } catch (Exception e) { conflictPolicy = ConflictPolicy.CONFLICT_REPLACE; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java index bb3bd59a38f..7f724829ef1 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java @@ -309,7 +309,7 @@ protected FieldWriter getWriter() { private FieldWriter promoteToUnion() { String name = vector.getField().getName(); - TransferPair tp = vector.getTransferPair(vector.getMinorType().name().toLowerCase(Locale.getDefault()), + TransferPair tp = vector.getTransferPair(vector.getMinorType().name().toLowerCase(Locale.ROOT), vector.getAllocator()); tp.transfer(); if (parentContainer != null) { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java b/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java index ef07b9f16de..95e35ce6938 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/util/Text.java @@ -202,9 +202,7 @@ public int find(String what, int start) { public void set(String string) { try { ByteBuffer bb = encode(string, true); - bytes = new byte[bb.remaining()]; - bb.get(bytes); - bb.position(bb.position() - bytes.length); // move it back so we can decode it + bytes = bb.array(); length = bb.limit(); } catch (CharacterCodingException e) { throw new RuntimeException("Should not have happened ", e); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java index 78cd77d1619..7dcbbfd9522 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java @@ -221,44 +221,42 @@ public void testSetLastSetUsage() throws Exception { offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(0), Integer.toString(offset)); - Long actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(10), actual); + long actual = dataVector.getObject(offset); + assertEquals(10L, actual); offset++; actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(11), actual); + assertEquals(11L, actual); offset++; actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(12), actual); + assertEquals(12L, actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(3), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(13), actual); + assertEquals(13L, actual); offset++; actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(14), actual); + assertEquals(14L, actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(5), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(15), actual); + assertEquals(15L, actual); offset++; actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(16), actual); + assertEquals(16L, actual); offset++; actual = dataVector.getObject(offset); - assertEquals(Long.valueOf(17), actual); + assertEquals(17L, actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(8), Integer.toString(offset)); - - actual = dataVector.getObject(offset); - assertNull(actual); + assertNull(dataVector.getObject(offset)); } } From ee8c00385b98d9df5cc9a8742d020df46f106fd3 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Fri, 19 Jan 2024 06:32:31 +0530 Subject: [PATCH 20/23] fix: address reviews v3 --- .../arrow/vector/TestLargeListVector.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java index 7dcbbfd9522..ffd87c99d50 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java @@ -221,42 +221,43 @@ public void testSetLastSetUsage() throws Exception { offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(0), Integer.toString(offset)); - long actual = dataVector.getObject(offset); - assertEquals(10L, actual); + Long actual = dataVector.getObject(offset); + assertEquals(Long.valueOf(10), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(11L, actual); + assertEquals(Long.valueOf(11), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(12L, actual); + assertEquals(Long.valueOf(12), actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(3), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(13L, actual); + assertEquals(Long.valueOf(13), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(14L, actual); + assertEquals(Long.valueOf(14), actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(5), Integer.toString(offset)); actual = dataVector.getObject(offset); - assertEquals(15L, actual); + assertEquals(Long.valueOf(15), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(16L, actual); + assertEquals(Long.valueOf(16), actual); offset++; actual = dataVector.getObject(offset); - assertEquals(17L, actual); + assertEquals(Long.valueOf(17), actual); index++; offset = (int) offsetBuffer.getLong(index * LargeListVector.OFFSET_WIDTH); assertEquals(Integer.toString(8), Integer.toString(offset)); - assertNull(dataVector.getObject(offset)); + actual = dataVector.getObject(offset); + assertNull(actual); } } From 14b23fffcafb513f3b9dfa7be37b939d1e30e0ab Mon Sep 17 00:00:00 2001 From: vibhatha Date: Fri, 19 Jan 2024 19:50:32 +0530 Subject: [PATCH 21/23] fix: addressing reviews v3 --- java/flight/flight-core/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/flight/flight-core/pom.xml b/java/flight/flight-core/pom.xml index b8cf6e3000c..61ddc5115eb 100644 --- a/java/flight/flight-core/pom.xml +++ b/java/flight/flight-core/pom.xml @@ -25,6 +25,7 @@ 1 + 3.23.1 @@ -89,7 +90,7 @@ com.google.protobuf protobuf-java-util - 3.23.1 + ${protobuf.version} io.grpc From 190e6dfd0fb0e5a2bdb632e542c4ac12f61c95b9 Mon Sep 17 00:00:00 2001 From: vibhatha Date: Mon, 22 Jan 2024 09:17:53 +0530 Subject: [PATCH 22/23] fix: addressing reviews v4 --- java/flight/flight-core/pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/java/flight/flight-core/pom.xml b/java/flight/flight-core/pom.xml index 61ddc5115eb..0346172f610 100644 --- a/java/flight/flight-core/pom.xml +++ b/java/flight/flight-core/pom.xml @@ -25,7 +25,6 @@ 1 - 3.23.1 @@ -90,7 +89,6 @@ com.google.protobuf protobuf-java-util - ${protobuf.version} io.grpc From c1cb67175bc635e514daa1f9b25ace9a3369946d Mon Sep 17 00:00:00 2001 From: vibhatha Date: Tue, 23 Jan 2024 09:01:30 +0530 Subject: [PATCH 23/23] fix: addressing reviews v5 --- .../java/org/apache/arrow/flight/FlightRuntimeException.java | 2 +- .../java/org/apache/arrow/flight/TestDictionaryUtils.java | 4 ++-- .../test/java/org/apache/arrow/flight/TestFlightService.java | 4 +--- .../driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java | 5 +---- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java index a22b4614cbf..76d3349a2c3 100644 --- a/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java +++ b/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightRuntimeException.java @@ -39,7 +39,7 @@ public CallStatus status() { } @Override - public String getMessage() { + public String toString() { String s = getClass().getName(); return String.format("%s: %s: %s", s, status.code(), status.description()); } diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java index 9e33136c107..40930131e0c 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestDictionaryUtils.java @@ -18,7 +18,7 @@ package org.apache.arrow.flight; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertSame; import java.util.TreeSet; @@ -79,7 +79,7 @@ public void testCreateSchema() { Schema newSchema = DictionaryUtils.generateSchema(schema, dictProvider, dictionaryUsed); // assert that a new schema is created. - assertNotEquals(schema, newSchema); + assertNotSame(schema, newSchema); // assert the column is converted as expected ArrowType newColType = newSchema.getFields().get(0).getType(); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java index b8ceb2cc61d..de1b7750da3 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightService.java @@ -155,9 +155,7 @@ public FlightInfo getFlightInfo(CallContext context, Exception e = Assertions.assertThrows( FlightRuntimeException.class, () -> client.getSchema(FlightDescriptor.path("test"))); - String expectedMessage = "org.apache.arrow.flight.FlightRuntimeException: INVALID_ARGUMENT:" + - " No schema is present in FlightInfo"; - Assertions.assertEquals(expectedMessage, e.getMessage()); + Assertions.assertEquals("No schema is present in FlightInfo", e.getMessage()); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java index 3f7edd03a7d..43209d8913e 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java @@ -207,12 +207,9 @@ public void testShouldFailToPrepareStatementForBadStatement() { * we simply throw an `IllegalArgumentException` for queries not registered * in our `MockFlightSqlProducer`. */ - String expectedMessage = format("Error while executing SQL \"%s\": " + - "org.apache.arrow.flight.FlightRuntimeException: INVALID_ARGUMENT: Query not found", - badQuery); collector.checkThat( e.getMessage(), - is(expectedMessage)); + is(format("Error while executing SQL \"%s\": Query not found", badQuery))); } collector.checkThat(count, is(1)); }