This is an automated email from the ASF dual-hosted git repository.
emkornfield pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 462e04b ARROW-5884: [Java] Fix the get method of StructVector
462e04b is described below
commit 462e04bac84cd1b6e49491e646fb7a63c1c66e51
Author: liyafan82 <[email protected]>
AuthorDate: Sat Jul 13 01:08:32 2019 -0700
ARROW-5884: [Java] Fix the get method of StructVector
When the data at the specified location is null, there is no need to call
the method from super to set the reader
holder.isSet = isSet(index);
super.get(index, holder);
Author: liyafan82 <[email protected]>
Closes #4831 from liyafan82/fly_0709_strnull and squashes the following
commits:
0b8f79886 <liyafan82> Force the reader to be null
49148aad2 <liyafan82> Fix the get method of StructVector
---
.../apache/arrow/vector/complex/StructVector.java | 4 +++
.../org/apache/arrow/vector/TestStructVector.java | 32 ++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git
a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java
b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java
index 35f50ef..a07e0d2 100644
---
a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java
+++
b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java
@@ -482,6 +482,10 @@ public class StructVector extends NonNullableStructVector
implements FieldVector
@Override
public void get(int index, ComplexHolder holder) {
holder.isSet = isSet(index);
+ if (holder.isSet == 0) {
+ holder.reader = null;
+ return;
+ }
super.get(index, holder);
}
diff --git
a/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java
b/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java
index 7706be4..9d156eb 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java
@@ -18,15 +18,20 @@
package org.apache.arrow.vector;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+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;
+
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -100,4 +105,31 @@ public class TestStructVector {
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);
+ vector.setIndexDefined(0);
+ intVector.setNull(1);
+ vector.setNull(1);
+
+ ComplexHolder holder = new ComplexHolder();
+ vector.get(0, holder);
+ assertNotEquals(0, holder.isSet);
+ assertNotNull(holder.reader);
+
+ vector.get(1, holder);
+ assertEquals(0, holder.isSet);
+ assertNull(holder.reader);
+ }
+ }
}