Repository: arrow Updated Branches: refs/heads/master 03134b11f -> bae33d622
ARROW-304: NullableMapReaderImpl.isSet() always returns true Author: Julien Le Dem <[email protected]> Closes #147 from julienledem/isSet and squashes the following commits: c06e048 [Julien Le Dem] review feedback 5a33785 [Julien Le Dem] review feedback af5d613 [Julien Le Dem] ARROW-304: NullableMapReaderImpl.isSet() always returns true Project: http://git-wip-us.apache.org/repos/asf/arrow/repo Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/bae33d62 Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/bae33d62 Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/bae33d62 Branch: refs/heads/master Commit: bae33d622421e6377ab3e9c81dd054c796ab48a3 Parents: 03134b1 Author: Julien Le Dem <[email protected]> Authored: Tue Sep 27 10:39:09 2016 -0700 Committer: Julien Le Dem <[email protected]> Committed: Tue Sep 27 10:39:09 2016 -0700 ---------------------------------------------------------------------- .../complex/impl/NullableMapReaderImpl.java | 5 ++ .../vector/complex/impl/UnionListReader.java | 2 +- .../complex/writer/TestComplexWriter.java | 57 +++++++++++++++++--- 3 files changed, 55 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/bae33d62/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/NullableMapReaderImpl.java ---------------------------------------------------------------------- diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/NullableMapReaderImpl.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/NullableMapReaderImpl.java index 18b35c1..7c389e6 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/NullableMapReaderImpl.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/NullableMapReaderImpl.java @@ -42,4 +42,9 @@ public class NullableMapReaderImpl extends SingleMapReaderImpl { NullableMapWriter impl = (NullableMapWriter) writer.map(name); impl.container.copyFromSafe(idx(), impl.idx(), nullableMapVector); } + + @Override + public boolean isSet(){ + return !nullableMapVector.getAccessor().isNull(idx()); + } } http://git-wip-us.apache.org/repos/asf/arrow/blob/bae33d62/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java ---------------------------------------------------------------------- diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java index 39cf004..6c7c230 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java @@ -41,7 +41,7 @@ public class UnionListReader extends AbstractFieldReader { @Override public boolean isSet() { - return true; + return !vector.getAccessor().isNull(idx()); } private int currentOffset; http://git-wip-us.apache.org/repos/asf/arrow/blob/bae33d62/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java ---------------------------------------------------------------------- diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java index fa710da..c1da104 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java @@ -17,6 +17,14 @@ */ package org.apache.arrow.vector.complex.writer; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.complex.ListVector; @@ -77,28 +85,33 @@ public class TestComplexWriter { MapVector parent = new MapVector("parent", allocator, null); ComplexWriter writer = new ComplexWriterImpl("root", parent); MapWriter rootWriter = writer.rootAsMap(); - MapWriter mapWriter = rootWriter.map("map"); - BigIntWriter nested = mapWriter.bigInt("nested"); for (int i = 0; i < COUNT; i++) { + rootWriter.setPosition(i); + rootWriter.start(); if (i % 2 == 0) { + MapWriter mapWriter = rootWriter.map("map"); mapWriter.setPosition(i); mapWriter.start(); - nested.writeBigInt(i); + mapWriter.bigInt("nested").writeBigInt(i); mapWriter.end(); } + rootWriter.end(); } writer.setValueCount(COUNT); MapReader rootReader = new SingleMapReaderImpl(parent).reader("root"); for (int i = 0; i < COUNT; i++) { rootReader.setPosition(i); + assertTrue("index is set: " + i, rootReader.isSet()); + FieldReader map = rootReader.reader("map"); if (i % 2 == 0) { - Assert.assertNotNull(rootReader.reader("map").readObject()); - Assert.assertEquals(i, rootReader.reader("map").reader("nested").readLong().longValue()); + assertTrue("index is set: " + i, map.isSet()); + assertNotNull("index is set: " + i, map.readObject()); + assertEquals(i, map.reader("nested").readLong().longValue()); } else { - Assert.assertNull(rootReader.reader("map").readObject()); + assertFalse("index is not set: " + i, map.isSet()); + assertNull("index is not set: " + i, map.readObject()); } } - parent.close(); } @@ -121,11 +134,39 @@ public class TestComplexWriter { listReader.setPosition(i); for (int j = 0; j < i % 7; j++) { listReader.next(); - Assert.assertEquals(j, listReader.reader().readInteger().intValue()); + assertEquals(j, listReader.reader().readInteger().intValue()); } } } + @Test + public void listScalarTypeNullable() { + ListVector listVector = new ListVector("list", allocator, null); + listVector.allocateNew(); + UnionListWriter listWriter = new UnionListWriter(listVector); + for (int i = 0; i < COUNT; i++) { + if (i % 2 == 0) { + listWriter.setPosition(i); + listWriter.startList(); + for (int j = 0; j < i % 7; j++) { + listWriter.writeInt(j); + } + listWriter.endList(); + } + } + listWriter.setValueCount(COUNT); + UnionListReader listReader = new UnionListReader(listVector); + for (int i = 0; i < COUNT; i++) { + listReader.setPosition(i); + if (i % 2 == 0) { + assertTrue("index is set: " + i, listReader.isSet()); + assertEquals("correct length at: " + i, i % 7, ((List<?>)listReader.readObject()).size()); + } else { + assertFalse("index is not set: " + i, listReader.isSet()); + assertNull("index is not set: " + i, listReader.readObject()); + } + } + } @Test public void listMapType() {
