Skip to content

Commit ea9008a

Browse files
committed
Revert "apacheGH-343: Fix ListVector offset buffer not properly serialized for nested empty arrays (apache#967)"
This reverts commit 0f8a080.
1 parent 2334954 commit ea9008a

4 files changed

Lines changed: 4 additions & 50 deletions

File tree

vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,11 @@ private void setReaderAndWriterIndex() {
309309
offsetBuffer.readerIndex(0);
310310
if (valueCount == 0) {
311311
validityBuffer.writerIndex(0);
312+
offsetBuffer.writerIndex(0);
312313
} else {
313314
validityBuffer.writerIndex(BitVectorHelper.getValidityBufferSizeFromCount(valueCount));
315+
offsetBuffer.writerIndex((valueCount + 1) * OFFSET_WIDTH);
314316
}
315-
// IPC serializer will determine readable bytes based on `readerIndex` and `writerIndex`.
316-
// Both are set to 0 means 0 bytes are written to the IPC stream which will crash IPC readers
317-
// in other libraries. According to Arrow spec, we should still output the offset buffer which
318-
// is [0].
319-
offsetBuffer.writerIndex((long) (valueCount + 1) * OFFSET_WIDTH);
320317
}
321318

322319
/**

vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,11 @@ private void setReaderAndWriterIndex() {
267267
offsetBuffer.readerIndex(0);
268268
if (valueCount == 0) {
269269
validityBuffer.writerIndex(0);
270+
offsetBuffer.writerIndex(0);
270271
} else {
271272
validityBuffer.writerIndex(BitVectorHelper.getValidityBufferSizeFromCount(valueCount));
273+
offsetBuffer.writerIndex((valueCount + 1) * OFFSET_WIDTH);
272274
}
273-
// IPC serializer will determine readable bytes based on `readerIndex` and `writerIndex`.
274-
// Both are set to 0 means 0 bytes are written to the IPC stream which will crash IPC readers
275-
// in other libraries. According to Arrow spec, we should still output the offset buffer which
276-
// is [0].
277-
offsetBuffer.writerIndex((long) (valueCount + 1) * OFFSET_WIDTH);
278275
}
279276

280277
/**

vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,26 +1100,6 @@ public void testCopyValueSafeForExtensionType() throws Exception {
11001100
}
11011101
}
11021102

1103-
@Test
1104-
public void testEmptyLargeListOffsetBuffer() {
1105-
// Test that LargeListVector has correct readableBytes after allocation.
1106-
// According to Arrow spec, offset buffer must have N+1 entries.
1107-
// Even when N=0, it should contain [0].
1108-
try (LargeListVector list = LargeListVector.empty("list", allocator)) {
1109-
list.addOrGetVector(FieldType.nullable(MinorType.INT.getType()));
1110-
list.allocateNew();
1111-
list.setValueCount(0);
1112-
1113-
List<ArrowBuf> buffers = list.getFieldBuffers();
1114-
assertTrue(
1115-
buffers.get(1).readableBytes() >= LargeListVector.OFFSET_WIDTH,
1116-
"Offset buffer should have at least "
1117-
+ LargeListVector.OFFSET_WIDTH
1118-
+ " bytes for offset[0]");
1119-
assertEquals(0L, list.getOffsetBuffer().getLong(0));
1120-
}
1121-
}
1122-
11231103
private void writeIntValues(UnionLargeListWriter writer, int[] values) {
11241104
writer.startList();
11251105
for (int v : values) {

vector/src/test/java/org/apache/arrow/vector/TestListVector.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,26 +1379,6 @@ public void testCopyValueSafeForExtensionType() throws Exception {
13791379
}
13801380
}
13811381

1382-
@Test
1383-
public void testEmptyListOffsetBuffer() {
1384-
// Test that ListVector has correct readableBytes after allocation.
1385-
// According to Arrow spec, offset buffer must have N+1 entries.
1386-
// Even when N=0, it should contain [0].
1387-
try (ListVector list = ListVector.empty("list", allocator)) {
1388-
list.addOrGetVector(FieldType.nullable(MinorType.INT.getType()));
1389-
list.allocateNew();
1390-
list.setValueCount(0);
1391-
1392-
List<ArrowBuf> buffers = list.getFieldBuffers();
1393-
assertTrue(
1394-
buffers.get(1).readableBytes() >= BaseRepeatedValueVector.OFFSET_WIDTH,
1395-
"Offset buffer should have at least "
1396-
+ BaseRepeatedValueVector.OFFSET_WIDTH
1397-
+ " bytes for offset[0]");
1398-
assertEquals(0, list.getOffsetBuffer().getInt(0));
1399-
}
1400-
}
1401-
14021382
private void writeIntValues(UnionListWriter writer, int[] values) {
14031383
writer.startList();
14041384
for (int v : values) {

0 commit comments

Comments
 (0)