-
Notifications
You must be signed in to change notification settings - Fork 119
GH-1098: [Java][Vector] Fix always-true precondition check in LargeListVector.setValueCount #1099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LuciferYang
wants to merge
2
commits into
apache:main
Choose a base branch
from
LuciferYang:fix-large-list-vector-precondition-logic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,14 +21,17 @@ | |
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| 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 static org.junit.jupiter.api.Assertions.fail; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import org.apache.arrow.memory.ArrowBuf; | ||
| import org.apache.arrow.memory.BufferAllocator; | ||
| import org.apache.arrow.memory.OutOfMemoryException; | ||
| import org.apache.arrow.vector.complex.BaseRepeatedValueVector; | ||
| import org.apache.arrow.vector.complex.LargeListVector; | ||
| import org.apache.arrow.vector.complex.ListVector; | ||
|
|
@@ -42,6 +45,7 @@ | |
| import org.apache.arrow.vector.types.pojo.ArrowType; | ||
| import org.apache.arrow.vector.types.pojo.Field; | ||
| import org.apache.arrow.vector.types.pojo.FieldType; | ||
| import org.apache.arrow.vector.util.OversizedAllocationException; | ||
| import org.apache.arrow.vector.util.TransferPair; | ||
| import org.apache.arrow.vector.util.UuidUtility; | ||
| import org.junit.jupiter.api.AfterEach; | ||
|
|
@@ -1127,4 +1131,89 @@ private void writeIntValues(UnionLargeListWriter writer, int[] values) { | |
| } | ||
| writer.endList(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetValueCountRejectsNegativeChildValueCount() { | ||
| try (final LargeListVector vector = LargeListVector.empty("list", allocator)) { | ||
| vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); | ||
| vector.allocateNew(); | ||
|
|
||
| // Write a negative value into the offset buffer to simulate a corrupted offset. | ||
| // The Preconditions check should reject any negative childValueCount. | ||
| vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, -1L); | ||
| vector.setLastSet(0); | ||
|
|
||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> vector.setValueCount(1), | ||
| "setValueCount should reject negative childValueCount"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetValueCountRejectsOverflowChildValueCount() { | ||
| try (final LargeListVector vector = LargeListVector.empty("list", allocator)) { | ||
| vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); | ||
| vector.allocateNew(); | ||
|
|
||
| // Write a value exceeding Integer.MAX_VALUE into the offset buffer | ||
| vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, (long) Integer.MAX_VALUE + 1L); | ||
| vector.setLastSet(0); | ||
|
|
||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> vector.setValueCount(1), | ||
| "setValueCount should reject childValueCount exceeding Integer.MAX_VALUE"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetValueCountAcceptsZeroChildValueCount() { | ||
| try (final LargeListVector vector = LargeListVector.empty("list", allocator)) { | ||
| vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); | ||
| vector.allocateNew(); | ||
|
|
||
| // childValueCount = 0 when valueCount = 0 (no elements) | ||
| vector.setValueCount(0); | ||
| assertEquals(0, vector.getValueCount()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetValueCountAcceptsValidChildValueCount() { | ||
| try (final LargeListVector vector = LargeListVector.empty("list", allocator)) { | ||
| vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); | ||
| vector.allocateNew(); | ||
|
|
||
| // Write a valid childValueCount (5) into the offset buffer | ||
| vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, 5L); | ||
| vector.setLastSet(0); | ||
| vector.setValueCount(1); | ||
| assertEquals(1, vector.getValueCount()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetValueCountAcceptsMaxIntChildValueCount() { | ||
| try (final LargeListVector vector = LargeListVector.empty("list", allocator)) { | ||
| vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); | ||
| vector.allocateNew(); | ||
|
|
||
| // Write Integer.MAX_VALUE into the offset buffer to verify the upper boundary is inclusive. | ||
| // The Preconditions check should accept this value (not throw IllegalArgumentException). | ||
| // The child vector may throw OversizedAllocationException due to memory limits, | ||
| // which is expected and unrelated to the precondition validation. | ||
| vector.getOffsetBuffer().setLong(LargeListVector.OFFSET_WIDTH, Integer.MAX_VALUE); | ||
| vector.setLastSet(0); | ||
| try { | ||
| vector.setValueCount(1); | ||
| } catch (IllegalArgumentException e) { | ||
| fail("setValueCount should not reject childValueCount = Integer.MAX_VALUE", e); | ||
| } catch (OversizedAllocationException | OutOfMemoryException e) { | ||
| // OversizedAllocationException or other allocation errors are expected | ||
| // when trying to allocate Integer.MAX_VALUE elements — this is fine, | ||
| // the precondition check itself passed. | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Maybe this can be replaced with
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1717f2e address the comments |
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message throwing here is a bit confusing:
IllegalArgument LargeListVector doesn't yet support 64-bit allocations: -1