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
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 <fan_li_ya@foxmail.com>

Closes #4831 from liyafan82/fly_0709_strnull and squashes the following commits:

0b8f798 <liyafan82>  Force the reader to be null
49148aa <liyafan82>  Fix the get method of StructVector
  • Loading branch information
liyafan82 authored and kszucs committed Jul 22, 2019
1 parent 9101c86 commit 9587ba2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ public Object getObject(int index) {
@Override
public void get(int index, ComplexHolder holder) {
holder.isSet = isSet(index);
if (holder.isSet == 0) {
holder.reader = null;
return;
}
super.get(index, holder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,4 +105,31 @@ 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);
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);
}
}
}

0 comments on commit 9587ba2

Please sign in to comment.