Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions c/src/test/java/org/apache/arrow/c/RoundtripTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.memory.util.hash.ArrowBufHasher;
import org.apache.arrow.vector.BaseLargeVariableWidthVector;
import org.apache.arrow.vector.BaseVariableWidthVector;
import org.apache.arrow.vector.BigIntVector;
import org.apache.arrow.vector.BitVector;
import org.apache.arrow.vector.DateDayVector;
Expand Down Expand Up @@ -77,6 +79,7 @@
import org.apache.arrow.vector.ValueVector;
import org.apache.arrow.vector.VarBinaryVector;
import org.apache.arrow.vector.VarCharVector;
import org.apache.arrow.vector.VariableWidthVector;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentional import? This is failing the build

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Other test failures seems to be unrelated to this PR.

import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.ViewVarBinaryVector;
import org.apache.arrow.vector.ViewVarCharVector;
Expand Down Expand Up @@ -181,6 +184,12 @@ boolean roundtrip(FieldVector vector, Class<?> clazz) {
clazz.isInstance(imported),
String.format("expected %s but was %s", clazz, imported.getClass()));
result = VectorEqualsVisitor.vectorEquals(vector, imported);

if (imported instanceof BaseVariableWidthVector || imported instanceof BaseLargeVariableWidthVector) {
ArrowBuf offsetBuffer = imported.getOffsetBuffer();
assertTrue(offsetBuffer.capacity() > 0);
assertEquals(0, offsetBuffer.getInt(0));
}
}

// Check that the ref counts of the buffers are the same after the roundtrip
Expand Down Expand Up @@ -602,6 +611,14 @@ public void testVarCharVector() {
}
}

@Test
public void testEmptyVarCharVector() {
try (final VarCharVector vector = new VarCharVector("v", allocator)) {
setVector(vector, new String[] {});
assertTrue(roundtrip(vector, VarCharVector.class));
}
}

@Test
public void testLargeVarBinaryVector() {
try (final LargeVarBinaryVector vector = new LargeVarBinaryVector("", allocator)) {
Expand Down Expand Up @@ -635,6 +652,14 @@ public void testLargeVarCharVector() {
}
}

@Test
public void testEmptyLargeVarCharVector() {
try (final LargeVarCharVector vector = new LargeVarCharVector("v", allocator)) {
setVector(vector, new String[] {});
assertTrue(roundtrip(vector, LargeVarCharVector.class));
}
}

@Test
public void testListVector() {
try (final ListVector vector = ListVector.empty("v", allocator)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ private void allocateBytes(final long valueBufferSize, final int valueCount) {
private ArrowBuf allocateOffsetBuffer(final long size) {
ArrowBuf offsetBuffer = allocator.buffer(size);
offsetBuffer.readerIndex(0);
initOffsetBuffer();
offsetBuffer.setZero(0, offsetBuffer.capacity());
return offsetBuffer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private ArrowBuf allocateOffsetBuffer(final long size) {
final int curSize = (int) size;
ArrowBuf offsetBuffer = allocator.buffer(curSize);
offsetBuffer.readerIndex(0);
initOffsetBuffer();
offsetBuffer.setZero(0, offsetBuffer.capacity());
return offsetBuffer;
}

Expand Down
Loading