Skip to content

Commit

Permalink
apacheGH-40038: [Java] The offset buffer of empty array with variable…
Browse files Browse the repository at this point in the history
…-size layout should not be empty
  • Loading branch information
viirya committed Feb 11, 2024
1 parent d989191 commit e57be3b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public BaseLargeVariableWidthVector(Field field, final BufferAllocator allocator
lastValueCapacity = INITIAL_VALUE_ALLOCATION - 1;
valueCount = 0;
lastSet = -1;
offsetBuffer = allocator.getEmpty();
// According to Arrow spec, the offsets buffer contains length + 1 elements
allocateOffsetBuffer(OFFSET_WIDTH);
validityBuffer = allocator.getEmpty();
valueBuffer = allocator.getEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public BaseVariableWidthVector(Field field, final BufferAllocator allocator) {
lastValueCapacity = INITIAL_VALUE_ALLOCATION - 1;
valueCount = 0;
lastSet = -1;
offsetBuffer = allocator.getEmpty();
// According to Arrow spec, the offsets buffer contains length + 1 elements
allocateOffsetBuffer(OFFSET_WIDTH);
validityBuffer = allocator.getEmpty();
valueBuffer = allocator.getEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ protected BaseRepeatedValueVector(String name, BufferAllocator allocator, CallBa
protected BaseRepeatedValueVector(String name, BufferAllocator allocator, FieldVector vector, CallBack callBack) {
super(allocator);
this.name = name;
this.offsetBuffer = allocator.getEmpty();
// According to Arrow spec, the offsets buffer contains length + 1 elements
allocateOffsetBuffer(OFFSET_WIDTH);
this.vector = Preconditions.checkNotNull(vector, "data vector cannot be null");
this.repeatedCallBack = callBack;
this.valueCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public void shutdown() {
allocator.close();
}

@Test
public void testEmptyLargeVarCharVector() {
LargeVarCharVector vector = new LargeVarCharVector("empty", allocator);
assertEquals(8, vector.getOffsetBuffer().capacity());
vector.close();
}

@Test
public void testTransfer() {
try (BufferAllocator childAllocator1 = allocator.newChildAllocator("child1", 1000000, 1000000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ public void testFixedType2() {
}
}

@Test
public void testEmptyVarCharVector() {
VarCharVector vector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator);
assertEquals(4, vector.getOffsetBuffer().capacity());
vector.close();
}

@Test /* VarCharVector */
public void testSizeOfValueBuffer() {
try (final VarCharVector vector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator)) {
Expand Down Expand Up @@ -3216,7 +3223,7 @@ public void testEmptyBufBehavior() {
assertEquals(1, vector.getOffsetBuffer().refCnt());
assertEquals(0, vector.getDataBuffer().capacity());
assertEquals(0, vector.getValidityBuffer().capacity());
assertEquals(0, vector.getOffsetBuffer().capacity());
assertEquals(4, vector.getOffsetBuffer().capacity());

vector.allocateNew(valueCount);
assertEquals(1, vector.getDataBuffer().refCnt());
Expand All @@ -3239,7 +3246,7 @@ public void testEmptyBufBehavior() {
assertEquals(1, vector.getValidityBuffer().refCnt());
assertEquals(1, vector.getOffsetBuffer().refCnt());
assertEquals(0, vector.getValidityBuffer().capacity());
assertEquals(0, vector.getOffsetBuffer().capacity());
assertEquals(4, vector.getOffsetBuffer().capacity());

vector.setValueCount(valueCount);
vector.allocateNewSafe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public void terminate() throws Exception {
allocator.close();
}

@Test
public void testEmptyVarCharList() {
ListVector vector = new ListVector("VarList", allocator,
FieldType.nullable(Types.MinorType.VARCHAR.getType()), null);
Assert.assertEquals(4, vector.getOffsetBuffer().capacity());
vector.close();
}

@Test
public void testVarCharListWithNulls() {
byte[] bytes = "a".getBytes(StandardCharsets.UTF_8);
Expand Down

0 comments on commit e57be3b

Please sign in to comment.