Skip to content

Commit

Permalink
[ARROW-5884][Java] Fix the get method of StructVector
Browse files Browse the repository at this point in the history
  • Loading branch information
liyafan82 committed Jul 9, 2019
1 parent 3f767ce commit 49148aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ public Object getObject(int index) {
@Override
public void get(int index, ComplexHolder holder) {
holder.isSet = isSet(index);
if (holder.isSet == 0) {
return;
}
super.get(index, holder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
package org.apache.arrow.vector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.util.HashMap;
import java.util.Map;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.StructVector;
import org.apache.arrow.vector.holders.ComplexHolder;
import org.apache.arrow.vector.types.Types.MinorType;
import org.apache.arrow.vector.types.pojo.ArrowType.Struct;
import org.apache.arrow.vector.types.pojo.FieldType;
Expand Down Expand Up @@ -100,4 +102,26 @@ public void testAllocateAfterReAlloc() throws Exception {
Assert.assertEquals(vector.getValueCapacity(), savedValueCapacity);
}
}

@Test
public void testReadNullValue() {
Map<String, String> metadata = new HashMap<>();
metadata.put("k1", "v1");
FieldType type = new FieldType(true, Struct.INSTANCE, null, metadata);
try (StructVector vector = new StructVector("struct", allocator, type, null)) {
MinorType childtype = MinorType.INT;
vector.addOrGet("intchild", FieldType.nullable(childtype.getType()), IntVector.class);
vector.setValueCount(2);

IntVector intVector = (IntVector) vector.getChild("intchild");
intVector.setSafe(0, 100);
intVector.setNull(1);

ComplexHolder holder = new ComplexHolder();
vector.get(1, holder);

assertEquals(0, holder.isSet);
assertNull(holder.reader);
}
}
}

0 comments on commit 49148aa

Please sign in to comment.