From a71d4f4ca93c7f0e5efa960e04bdbe382c9994ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lder=20Greg=C3=B3rio?= Date: Wed, 14 Oct 2026 22:31:28 +0100 Subject: [PATCH 1/2] BDX-1590: Append Flight dictionary deltas --- .../org/apache/arrow/flight/FlightStream.java | 23 +- .../TestFlightStreamDictionaryDelta.java | 340 ++++++++++++++++++ 2 files changed, 356 insertions(+), 7 deletions(-) create mode 100644 flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java diff --git a/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java b/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java index 15cfd6ba85..82cfdd2311 100644 --- a/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java +++ b/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightStream.java @@ -46,6 +46,7 @@ import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.Schema; import org.apache.arrow.vector.util.DictionaryUtility; +import org.apache.arrow.vector.util.VectorBatchAppender; import org.apache.arrow.vector.validate.MetadataV4UnionChecker; /** An adaptor between protobuf streams and flight data streams. */ @@ -291,13 +292,21 @@ public boolean next() { } final FieldVector vector = dictionary.getVector(); - final VectorSchemaRoot dictionaryRoot = - new VectorSchemaRoot( - Collections.singletonList(vector.getField()), - Collections.singletonList(vector), - 0); - final VectorLoader dictionaryLoader = new VectorLoader(dictionaryRoot); - dictionaryLoader.load(arb.getDictionary()); + if (arb.isDelta()) { + try (FieldVector deltaVector = vector.getField().createVector(allocator)) { + final VectorSchemaRoot deltaRoot = VectorSchemaRoot.of(deltaVector); + new VectorLoader(deltaRoot).load(arb.getDictionary()); + VectorBatchAppender.batchAppend(vector, deltaVector); + } + } else { + final VectorSchemaRoot dictionaryRoot = + new VectorSchemaRoot( + Collections.singletonList(vector.getField()), + Collections.singletonList(vector), + 0); + final VectorLoader dictionaryLoader = new VectorLoader(dictionaryRoot); + dictionaryLoader.load(arb.getDictionary()); + } } return next(); } else { diff --git a/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java b/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java new file mode 100644 index 0000000000..e9b24645a1 --- /dev/null +++ b/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java @@ -0,0 +1,340 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.arrow.flight; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import io.grpc.MethodDescriptor; +import io.grpc.stub.StreamObserver; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.apache.arrow.memory.ArrowBuf; +import org.apache.arrow.memory.RootAllocator; +import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.ValueVector; +import org.apache.arrow.vector.VarCharVector; +import org.apache.arrow.vector.VectorSchemaRoot; +import org.apache.arrow.vector.VectorUnloader; +import org.apache.arrow.vector.dictionary.DictionaryEncoder; +import org.apache.arrow.vector.dictionary.DictionaryProvider; +import org.apache.arrow.vector.ipc.message.ArrowDictionaryBatch; +import org.apache.arrow.vector.ipc.message.IpcOption; +import org.apache.arrow.vector.types.pojo.ArrowType; +import org.apache.arrow.vector.types.pojo.DictionaryEncoding; +import org.apache.arrow.vector.types.pojo.Field; +import org.apache.arrow.vector.types.pojo.FieldType; +import org.apache.arrow.vector.types.pojo.Schema; +import org.junit.jupiter.api.Test; + +/** Tests dictionary updates received as framed Flight messages. */ +public class TestFlightStreamDictionaryDelta { + private static final DictionaryEncoding ENCODING = + new DictionaryEncoding(7, false, new ArrowType.Int(32, true)); + private static final Schema WIRE_SCHEMA = schema(ArrowType.Utf8.INSTANCE, ENCODING); + private static final Schema MEMORY_SCHEMA = schema(new ArrowType.Int(32, true), ENCODING); + + @Test + public void dictionaryDeltaAndReplacement() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + final DictionaryProvider provider = incoming.stream.getDictionaryProvider(); + assertEquals(MEMORY_SCHEMA, incoming.stream.getSchema()); + assertEquals(Collections.emptyList(), values(provider.lookup(7).getVector())); + incoming.dictionary(7, false, "alpha", "beta"); + incoming.batch(0, 1); + assertTrue(incoming.stream.next()); + final List captured = incoming.decode(); + assertEquals(Arrays.asList("alpha", "beta"), captured); + + incoming.dictionary(7, true); + incoming.dictionary(7, true, "gamma"); + incoming.batch(2, 0, null); + assertTrue(incoming.stream.next()); + assertSame(provider, incoming.stream.getDictionaryProvider()); + assertEquals(Arrays.asList("alpha", "beta", "gamma"), values(provider.lookup(7).getVector())); + assertEquals(Arrays.asList("gamma", "alpha", null), incoming.decode()); + + incoming.dictionary(7, false, "delta", "epsilon"); + incoming.batch(1, 0); + assertTrue(incoming.stream.next()); + assertEquals(Arrays.asList("epsilon", "delta"), incoming.decode()); + assertEquals(Arrays.asList("delta", "epsilon"), values(provider.lookup(7).getVector())); + assertEquals(Arrays.asList("alpha", "beta"), captured); + incoming.observer.onCompleted(); + assertFalse(incoming.stream.next()); + } + } + + @Test + public void undefinedDictionaryFailsAndClosesMessages() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + incoming.dictionary(7, false, "alpha", "beta"); + incoming.batch(1, 0); + assertTrue(incoming.stream.next()); + assertEquals(Arrays.asList("beta", "alpha"), incoming.decode()); + incoming.dictionary(8, true, "gamma"); + incoming.batch(0); + assertEquals( + "Dictionary not defined in schema: ID 8", + assertThrows(IllegalArgumentException.class, incoming.stream::next).getMessage()); + } + } + + @Test + public void invalidDictionaryIndexFailsAfterDelta() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + incoming.dictionary(7, false, "alpha", "beta"); + incoming.dictionary(7, true, "gamma"); + incoming.batch(2, 0, null); + assertTrue(incoming.stream.next()); + assertEquals(Arrays.asList("gamma", "alpha", null), incoming.decode()); + incoming.batch(3); + assertTrue(incoming.stream.next()); + assertThrows(IllegalArgumentException.class, incoming::decode); + } + } + + @Test + public void cancellationDrainsDeltaAndReleasesBuffers() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, true)) { + incoming.dictionary(7, false, "alpha", "beta"); + incoming.batch(0, 1); + assertTrue(incoming.stream.next()); + assertEquals(Arrays.asList("alpha", "beta"), incoming.decode()); + incoming.dictionary(7, true, "gamma"); + incoming.batch(2, null); + incoming.stream.cancel("cancel dictionary stream", null); + assertTrue(incoming.stream.next()); + assertEquals(Arrays.asList("gamma", null), incoming.decode()); + final FlightRuntimeException failure = + assertThrows(FlightRuntimeException.class, incoming.stream::next); + assertEquals(FlightStatusCode.CANCELLED, failure.status().code()); + assertEquals("cancel dictionary stream", failure.status().description()); + assertEquals(1, incoming.cancellations); + } + } + + @Test + public void lateErrorPreservesCapturedValuesAndReleasesBuffers() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + incoming.dictionary(7, false, "alpha", "beta"); + incoming.batch(0, 1); + assertTrue(incoming.stream.next()); + final List captured = incoming.decode(); + assertEquals(Arrays.asList("alpha", "beta"), captured); + incoming.dictionary(7, true, "gamma"); + incoming.batch(2); + incoming.observer.onError( + CallStatus.INTERNAL.withDescription("late failure").toRuntimeException()); + assertTrue(incoming.stream.next()); + assertEquals(Collections.singletonList("gamma"), incoming.decode()); + final FlightRuntimeException failure = + assertThrows(FlightRuntimeException.class, incoming.stream::next); + assertEquals(FlightStatusCode.INTERNAL, failure.status().code()); + assertEquals("late failure", failure.status().description()); + assertEquals(Arrays.asList("alpha", "beta"), captured); + } + } + + @Test + public void closeReleasesQueuedDictionaryAndRecordMessages() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + incoming.dictionary(7, false, "alpha", "beta"); + incoming.dictionary(7, true, "gamma"); + incoming.batch(2, 0, null); + assertTrue(incoming.stream.next()); + assertEquals(Arrays.asList("gamma", "alpha", null), incoming.decode()); + incoming.dictionary(7, true, "delta"); + incoming.batch(3); + } + } + + @Test + public void dictionaryOwnershipSurvivesStreamClose() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + incoming.dictionary(7, false, "alpha", "beta"); + incoming.dictionary(7, true, "gamma"); + incoming.batch(2, 0); + incoming.observer.onCompleted(); + assertTrue(incoming.stream.next()); + assertEquals(Arrays.asList("gamma", "alpha"), incoming.decode()); + assertFalse(incoming.stream.next()); + final DictionaryProvider borrowed = incoming.stream.getDictionaryProvider(); + try (DictionaryProvider.MapDictionaryProvider owned = + (DictionaryProvider.MapDictionaryProvider) incoming.stream.takeDictionaryOwnership()) { + assertSame(borrowed, owned); + assertThrows(IllegalStateException.class, incoming.stream::takeDictionaryOwnership); + assertThrows(IllegalStateException.class, incoming.stream::getDictionaryProvider); + incoming.stream.close(); + assertEquals(Arrays.asList("alpha", "beta", "gamma"), values(owned.lookup(7).getVector())); + } + assertEquals(0, incoming.allocator.getAllocatedMemory()); + } + } + + @Test + public void zeroRowBatchAndSchemaOnlyStream() throws Exception { + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + incoming.dictionary(7, false, "alpha", "beta"); + incoming.dictionary(7, true); + incoming.batch(); + incoming.observer.onCompleted(); + assertTrue(incoming.stream.next()); + assertEquals(MEMORY_SCHEMA, incoming.stream.getSchema()); + assertEquals(Collections.emptyList(), incoming.decode()); + assertEquals( + Arrays.asList("alpha", "beta"), + values(incoming.stream.getDictionaryProvider().lookup(7).getVector())); + assertFalse(incoming.stream.next()); + } + try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { + incoming.observer.onCompleted(); + assertEquals(MEMORY_SCHEMA, incoming.stream.getSchema()); + assertFalse(incoming.stream.next()); + assertEquals( + Collections.emptyList(), + values(incoming.stream.getDictionaryProvider().lookup(7).getVector())); + } + } + + @Test + public void nonDictionaryStreamKeepsSchemaAndValues() throws Exception { + final Schema plainSchema = schema(new ArrowType.Int(32, true), null); + try (TestStream incoming = new TestStream(plainSchema, false)) { + incoming.batch(2, 0, null); + incoming.observer.onCompleted(); + assertTrue(incoming.stream.next()); + assertEquals(plainSchema, incoming.stream.getSchema()); + assertEquals(Arrays.asList("2", "0", null), values(incoming.stream.getRoot().getVector(0))); + assertEquals( + Collections.emptySet(), incoming.stream.getDictionaryProvider().getDictionaryIds()); + assertFalse(incoming.stream.next()); + } + } + + private static Schema schema(ArrowType type, DictionaryEncoding encoding) { + return new Schema( + Collections.singletonList( + new Field( + "word", + new FieldType(true, type, encoding, Map.of("field", "words")), + Collections.emptyList())), + Map.of("stream", "dictionary-delta")); + } + + private static List values(ValueVector vector) { + final List values = new ArrayList<>(); + for (int i = 0; i < vector.getValueCount(); i++) { + final Object value = vector.getObject(i); + values.add(value == null ? null : value.toString()); + } + return values; + } + + private static final class TestStream implements AutoCloseable { + private final RootAllocator allocator = new RootAllocator(1 << 20); + private final FlightStream stream; + private final StreamObserver observer; + private final List receivedBuffers = new ArrayList<>(); + private int cancellations; + + private TestStream(Schema schema, boolean cancellable) throws Exception { + stream = new FlightStream(allocator, 2, cancellable ? this::cancel : null, count -> {}); + observer = stream.asObserver(); + push(new ArrowMessage(null, schema, IpcOption.DEFAULT)); + } + + private void cancel(String message, Throwable exception) { + cancellations++; + observer.onError( + CallStatus.CANCELLED.withDescription(message).withCause(exception).toRuntimeException()); + } + + private void dictionary(long id, boolean delta, String... words) throws Exception { + try (VarCharVector vector = new VarCharVector("dictionary", allocator); + VectorSchemaRoot root = VectorSchemaRoot.of(vector)) { + vector.allocateNew(); + for (int i = 0; i < words.length; i++) { + vector.setSafe(i, words[i].getBytes(StandardCharsets.UTF_8)); + } + root.setRowCount(words.length); + try (ArrowDictionaryBatch batch = + new ArrowDictionaryBatch(id, new VectorUnloader(root).getRecordBatch(), delta)) { + push(new ArrowMessage(batch, IpcOption.DEFAULT)); + } + } + } + + private void batch(Integer... indices) throws Exception { + try (IntVector vector = new IntVector("word", allocator); + VectorSchemaRoot root = VectorSchemaRoot.of(vector)) { + vector.allocateNew(indices.length); + for (int i = 0; i < indices.length; i++) { + if (indices[i] == null) { + vector.setNull(i); + } else { + vector.setSafe(i, indices[i]); + } + } + root.setRowCount(indices.length); + push( + new ArrowMessage( + new VectorUnloader(root).getRecordBatch(), null, false, IpcOption.DEFAULT)); + } + } + + private void push(ArrowMessage message) throws Exception { + final MethodDescriptor.Marshaller marshaller = + ArrowMessage.createMarshaller(allocator); + try (message; + InputStream wire = marshaller.stream(message)) { + final ArrowMessage received = marshaller.parse(wire); + received.getBufs().forEach(receivedBuffers::add); + observer.onNext(received); + } + } + + private List decode() { + try (ValueVector decoded = + DictionaryEncoder.decode( + stream.getRoot().getVector(0), stream.getDictionaryProvider().lookup(7))) { + return values(decoded); + } + } + + @Override + public void close() throws Exception { + try (allocator) { + stream.close(); + assertEquals( + receivedBuffers.stream().map(buffer -> buffer.capacity() == 0 ? 1 : 0).toList(), + receivedBuffers.stream() + .map(buffer -> buffer.getReferenceManager().getRefCount()) + .toList()); + assertEquals(0, allocator.getAllocatedMemory()); + } + } + } +} From 86fbde3be1994490bdad3fb192c5abf6c2b84e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lder=20Greg=C3=B3rio?= Date: Wed, 14 Oct 2026 22:54:45 +0100 Subject: [PATCH 2/2] BDX-1590: Append Null vector counts --- .../TestFlightStreamDictionaryDelta.java | 45 +++++++++++++ .../arrow/vector/util/VectorAppender.java | 2 + .../arrow/vector/util/TestVectorAppender.java | 63 +++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java b/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java index e9b24645a1..185008b71d 100644 --- a/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java +++ b/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightStreamDictionaryDelta.java @@ -34,6 +34,7 @@ import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.NullVector; import org.apache.arrow.vector.ValueVector; import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.VectorSchemaRoot; @@ -56,6 +57,40 @@ public class TestFlightStreamDictionaryDelta { private static final Schema WIRE_SCHEMA = schema(ArrowType.Utf8.INSTANCE, ENCODING); private static final Schema MEMORY_SCHEMA = schema(new ArrowType.Int(32, true), ENCODING); + @Test + public void nullDictionaryDeltaAndReplacement() throws Exception { + try (TestStream incoming = new TestStream(schema(ArrowType.Null.INSTANCE, ENCODING), false)) { + final DictionaryProvider provider = incoming.stream.getDictionaryProvider(); + assertEquals(MEMORY_SCHEMA, incoming.stream.getSchema()); + incoming.nullDictionary(false, 1); + incoming.batch(0); + assertTrue(incoming.stream.next()); + final List captured = incoming.decode(); + assertEquals(Collections.singletonList(null), captured); + assertEquals(Collections.singletonList(null), values(provider.lookup(7).getVector())); + + incoming.nullDictionary(true, 0); + incoming.nullDictionary(true, 1); + incoming.batch(1); + assertTrue(incoming.stream.next()); + assertEquals(Collections.singletonList(null), incoming.decode()); + assertEquals(Arrays.asList(null, null), values(provider.lookup(7).getVector())); + assertSame(provider, incoming.stream.getDictionaryProvider()); + + incoming.nullDictionary(false, 1); + incoming.batch(0); + assertTrue(incoming.stream.next()); + assertEquals(Collections.singletonList(null), incoming.decode()); + assertEquals(Collections.singletonList(null), values(provider.lookup(7).getVector())); + incoming.batch(1); + assertTrue(incoming.stream.next()); + assertThrows(IllegalArgumentException.class, incoming::decode); + assertEquals(Collections.singletonList(null), captured); + incoming.observer.onCompleted(); + assertFalse(incoming.stream.next()); + } + } + @Test public void dictionaryDeltaAndReplacement() throws Exception { try (TestStream incoming = new TestStream(WIRE_SCHEMA, false)) { @@ -305,6 +340,16 @@ private void batch(Integer... indices) throws Exception { } } + private void nullDictionary(boolean delta, int count) throws Exception { + try (VectorSchemaRoot root = VectorSchemaRoot.of(new NullVector("dictionary"))) { + root.setRowCount(count); + try (ArrowDictionaryBatch batch = + new ArrowDictionaryBatch(7, new VectorUnloader(root).getRecordBatch(), delta)) { + push(new ArrowMessage(batch, IpcOption.DEFAULT)); + } + } + } + private void push(ArrowMessage message) throws Exception { final MethodDescriptor.Marshaller marshaller = ArrowMessage.createMarshaller(allocator); diff --git a/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java b/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java index 7176e86c71..7a302b09cf 100644 --- a/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java +++ b/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java @@ -736,6 +736,8 @@ public ValueVector visit(NullVector deltaVector, Void value) { Preconditions.checkArgument( targetVector.getField().getType().equals(deltaVector.getField().getType()), "The targetVector to append must have the same type as the targetVector being appended"); + targetVector.setValueCount( + Math.addExact(targetVector.getValueCount(), deltaVector.getValueCount())); return targetVector; } diff --git a/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java b/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java index 57dd852e31..c2cc0df02e 100644 --- a/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java +++ b/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java @@ -17,6 +17,7 @@ package org.apache.arrow.vector.util; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -39,6 +40,7 @@ import org.apache.arrow.vector.Float4Vector; import org.apache.arrow.vector.IntVector; import org.apache.arrow.vector.LargeVarCharVector; +import org.apache.arrow.vector.NullVector; import org.apache.arrow.vector.TestUtils; import org.apache.arrow.vector.ValueVector; import org.apache.arrow.vector.VarCharVector; @@ -82,6 +84,67 @@ public void shutdown() { allocator.close(); } + @Test + public void testAppendNullVector() { + try (NullVector target = new NullVector("target"); + NullVector delta = new NullVector("delta", 2); + NullVector empty = new NullVector("empty")) { + VectorAppender appender = new VectorAppender(target); + assertSame(target, empty.accept(appender, null)); + assertEquals( + Collections.emptyList(), + IntStream.range(0, target.getValueCount()).mapToObj(target::getObject).toList()); + assertSame(target, delta.accept(appender, null)); + assertEquals( + Arrays.asList(null, null), + IntStream.range(0, target.getValueCount()).mapToObj(target::getObject).toList()); + VectorBatchAppender.batchAppend(target, empty, delta, delta); + assertEquals( + Arrays.asList(null, null, null, null, null, null), + IntStream.range(0, target.getValueCount()).mapToObj(target::getObject).toList()); + assertEquals( + Arrays.asList(null, null), + IntStream.range(0, delta.getValueCount()).mapToObj(delta::getObject).toList()); + assertEquals(0, allocator.getAllocatedMemory()); + } + } + + @Test + public void testAppendNullVectorTypeMismatch() { + try (NullVector nulls = new NullVector("nulls", 1); + IntVector integers = new IntVector("integers", allocator)) { + ValueVectorDataPopulator.setVector(integers, 42); + assertThrows( + IllegalArgumentException.class, () -> nulls.accept(new VectorAppender(integers), null)); + assertThrows( + IllegalArgumentException.class, () -> integers.accept(new VectorAppender(nulls), null)); + assertEquals( + Collections.singletonList(42), + IntStream.range(0, integers.getValueCount()).mapToObj(integers::getObject).toList()); + assertEquals( + Collections.singletonList(null), + IntStream.range(0, nulls.getValueCount()).mapToObj(nulls::getObject).toList()); + } + assertEquals(0, allocator.getAllocatedMemory()); + } + + @Test + public void testAppendNullVectorCountBoundary() { + try (NullVector target = new NullVector("target", Integer.MAX_VALUE - 1); + NullVector delta = new NullVector("delta", 1); + NullVector empty = new NullVector("empty")) { + VectorBatchAppender.batchAppend(target, delta, empty); + assertEquals( + List.of(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + List.of(target.getValueCount(), target.getNullCount(), target.getValueCapacity())); + assertThrows(ArithmeticException.class, () -> VectorBatchAppender.batchAppend(target, delta)); + assertEquals( + List.of(Integer.MAX_VALUE, 1, 0), + List.of(target.getValueCount(), delta.getValueCount(), empty.getValueCount())); + assertEquals(0, allocator.getAllocatedMemory()); + } + } + @Test public void testAppendFixedWidthVector() { final int length1 = 10;