sunchao commented on a change in pull request #11709:
URL: https://github.com/apache/arrow/pull/11709#discussion_r766867771
##########
File path:
java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java
##########
@@ -222,6 +223,59 @@ public void testConcatBitsInPlace() {
}
}
+ @Test
+ public void testLoadValidityBuffer() {
+ try (RootAllocator allocator = new RootAllocator(1024)) {
+ // if the input validity buffer is all null, we should allocate new
memory
+ ArrowFieldNode fieldNode = new ArrowFieldNode(1024, 1024);
+ try (ArrowBuf buf = BitVectorHelper.loadValidityBuffer(fieldNode, null,
allocator)) {
+ assertEquals(128, allocator.getAllocatedMemory());
+ for (int i = 0; i < 128; i++) {
+ assertEquals(0, buf.getByte(i));
+ }
+ }
+
+ // should also allocate memory if input validity buffer is all not-null
+ fieldNode = new ArrowFieldNode(1024, 0);
+ try (ArrowBuf buf = BitVectorHelper.loadValidityBuffer(fieldNode, null,
allocator)) {
+ assertEquals(128, allocator.getAllocatedMemory());
+ for (int i = 0; i < 128; i++) {
+ assertEquals((byte) 0xff, buf.getByte(i));
+ }
+ }
+
+ // should not allocate memory if input validity buffer is not null, even
if all values are
+ // null
+ fieldNode = new ArrowFieldNode(1024, 1024);
+ try (ArrowBuf src = allocator.buffer(128);
+ ArrowBuf dst = BitVectorHelper.loadValidityBuffer(fieldNode, src,
allocator)) {
+ assertEquals(128, allocator.getAllocatedMemory());
+ }
+
+ // ... similarly if all values are not null
+ fieldNode = new ArrowFieldNode(1024, 0);
+ try (ArrowBuf src = allocator.buffer(128);
+ ArrowBuf dst = BitVectorHelper.loadValidityBuffer(fieldNode, src,
allocator)) {
+ assertEquals(128, allocator.getAllocatedMemory());
+ }
+
+ // mixed case, input should match output
+ int numNulls = 100;
+ fieldNode = new ArrowFieldNode(1024, numNulls);
+ try (ArrowBuf src = allocator.buffer(128)) {
+ for (int i = 0; i < numNulls; i++) {
+ BitVectorHelper.setBit(src, i);
+ }
+ try (ArrowBuf dst = BitVectorHelper.loadValidityBuffer(fieldNode, src,
allocator)) {
+ assertEquals(128, allocator.getAllocatedMemory());
Review comment:
We can't compare by reference since `dst` is a different `ArrowBuf`
object (see `ReferenceManager.retain`). I added a comparison on memory address
of these two.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]