File tree Expand file tree Collapse file tree
main/java/org/apache/arrow/vector/complex
test/java/org/apache/arrow/vector Expand file tree Collapse file tree Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments