Skip to content

Commit 9c1173d

Browse files
julienledemkou
authored andcommitted
ARROW-304: NullableMapReaderImpl.isSet() always returns true
Author: Julien Le Dem <julien@dremio.com> Closes apache#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
1 parent 75ae9dd commit 9c1173d

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

vector/src/main/java/org/apache/arrow/vector/complex/impl/NullableMapReaderImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ public void copyAsField(String name, MapWriter writer){
4242
NullableMapWriter impl = (NullableMapWriter) writer.map(name);
4343
impl.container.copyFromSafe(idx(), impl.idx(), nullableMapVector);
4444
}
45+
46+
@Override
47+
public boolean isSet(){
48+
return !nullableMapVector.getAccessor().isNull(idx());
49+
}
4550
}

vector/src/main/java/org/apache/arrow/vector/complex/impl/UnionListReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public UnionListReader(ListVector vector) {
4141

4242
@Override
4343
public boolean isSet() {
44-
return true;
44+
return !vector.getAccessor().isNull(idx());
4545
}
4646

4747
private int currentOffset;

vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
*/
1818
package org.apache.arrow.vector.complex.writer;
1919

20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertNull;
24+
import static org.junit.Assert.assertTrue;
25+
26+
import java.util.List;
27+
2028
import org.apache.arrow.memory.BufferAllocator;
2129
import org.apache.arrow.memory.RootAllocator;
2230
import org.apache.arrow.vector.complex.ListVector;
@@ -77,28 +85,33 @@ public void nullableMap() {
7785
MapVector parent = new MapVector("parent", allocator, null);
7886
ComplexWriter writer = new ComplexWriterImpl("root", parent);
7987
MapWriter rootWriter = writer.rootAsMap();
80-
MapWriter mapWriter = rootWriter.map("map");
81-
BigIntWriter nested = mapWriter.bigInt("nested");
8288
for (int i = 0; i < COUNT; i++) {
89+
rootWriter.setPosition(i);
90+
rootWriter.start();
8391
if (i % 2 == 0) {
92+
MapWriter mapWriter = rootWriter.map("map");
8493
mapWriter.setPosition(i);
8594
mapWriter.start();
86-
nested.writeBigInt(i);
95+
mapWriter.bigInt("nested").writeBigInt(i);
8796
mapWriter.end();
8897
}
98+
rootWriter.end();
8999
}
90100
writer.setValueCount(COUNT);
91101
MapReader rootReader = new SingleMapReaderImpl(parent).reader("root");
92102
for (int i = 0; i < COUNT; i++) {
93103
rootReader.setPosition(i);
104+
assertTrue("index is set: " + i, rootReader.isSet());
105+
FieldReader map = rootReader.reader("map");
94106
if (i % 2 == 0) {
95-
Assert.assertNotNull(rootReader.reader("map").readObject());
96-
Assert.assertEquals(i, rootReader.reader("map").reader("nested").readLong().longValue());
107+
assertTrue("index is set: " + i, map.isSet());
108+
assertNotNull("index is set: " + i, map.readObject());
109+
assertEquals(i, map.reader("nested").readLong().longValue());
97110
} else {
98-
Assert.assertNull(rootReader.reader("map").readObject());
111+
assertFalse("index is not set: " + i, map.isSet());
112+
assertNull("index is not set: " + i, map.readObject());
99113
}
100114
}
101-
102115
parent.close();
103116
}
104117

@@ -121,11 +134,39 @@ public void listScalarType() {
121134
listReader.setPosition(i);
122135
for (int j = 0; j < i % 7; j++) {
123136
listReader.next();
124-
Assert.assertEquals(j, listReader.reader().readInteger().intValue());
137+
assertEquals(j, listReader.reader().readInteger().intValue());
125138
}
126139
}
127140
}
128141

142+
@Test
143+
public void listScalarTypeNullable() {
144+
ListVector listVector = new ListVector("list", allocator, null);
145+
listVector.allocateNew();
146+
UnionListWriter listWriter = new UnionListWriter(listVector);
147+
for (int i = 0; i < COUNT; i++) {
148+
if (i % 2 == 0) {
149+
listWriter.setPosition(i);
150+
listWriter.startList();
151+
for (int j = 0; j < i % 7; j++) {
152+
listWriter.writeInt(j);
153+
}
154+
listWriter.endList();
155+
}
156+
}
157+
listWriter.setValueCount(COUNT);
158+
UnionListReader listReader = new UnionListReader(listVector);
159+
for (int i = 0; i < COUNT; i++) {
160+
listReader.setPosition(i);
161+
if (i % 2 == 0) {
162+
assertTrue("index is set: " + i, listReader.isSet());
163+
assertEquals("correct length at: " + i, i % 7, ((List<?>)listReader.readObject()).size());
164+
} else {
165+
assertFalse("index is not set: " + i, listReader.isSet());
166+
assertNull("index is not set: " + i, listReader.readObject());
167+
}
168+
}
169+
}
129170

130171
@Test
131172
public void listMapType() {

0 commit comments

Comments
 (0)