1717 */
1818package 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+
2028import org .apache .arrow .memory .BufferAllocator ;
2129import org .apache .arrow .memory .RootAllocator ;
2230import org .apache .arrow .vector .complex .ListVector ;
@@ -91,11 +99,14 @@ public void nullableMap() {
9199 MapReader rootReader = new SingleMapReaderImpl (parent ).reader ("root" );
92100 for (int i = 0 ; i < COUNT ; i ++) {
93101 rootReader .setPosition (i );
102+ FieldReader map = rootReader .reader ("map" );
94103 if (i % 2 == 0 ) {
95- Assert .assertNotNull (rootReader .reader ("map" ).readObject ());
96- Assert .assertEquals (i , rootReader .reader ("map" ).reader ("nested" ).readLong ().longValue ());
104+ assertTrue ("index is set: " + i , map .isSet ());
105+ assertNotNull ("index is set: " + i , map .readObject ());
106+ assertEquals (i , map .reader ("nested" ).readLong ().longValue ());
97107 } else {
98- Assert .assertNull (rootReader .reader ("map" ).readObject ());
108+ assertFalse ("index is not set: " + i , map .isSet ());
109+ assertNull ("index is not set: " + i , map .readObject ());
99110 }
100111 }
101112
@@ -121,11 +132,39 @@ public void listScalarType() {
121132 listReader .setPosition (i );
122133 for (int j = 0 ; j < i % 7 ; j ++) {
123134 listReader .next ();
124- Assert . assertEquals (j , listReader .reader ().readInteger ().intValue ());
135+ assertEquals (j , listReader .reader ().readInteger ().intValue ());
125136 }
126137 }
127138 }
128139
140+ @ Test
141+ public void listScalarTypeNullable () {
142+ ListVector listVector = new ListVector ("list" , allocator , null );
143+ listVector .allocateNew ();
144+ UnionListWriter listWriter = new UnionListWriter (listVector );
145+ for (int i = 0 ; i < COUNT ; i ++) {
146+ if (i % 2 == 0 ) {
147+ listWriter .setPosition (i );
148+ listWriter .startList ();
149+ for (int j = 0 ; j < i % 7 ; j ++) {
150+ listWriter .writeInt (j );
151+ }
152+ listWriter .endList ();
153+ }
154+ }
155+ listWriter .setValueCount (COUNT );
156+ UnionListReader listReader = new UnionListReader (listVector );
157+ for (int i = 0 ; i < COUNT ; i ++) {
158+ listReader .setPosition (i );
159+ if (i % 2 == 0 ) {
160+ assertTrue ("index is set: " + i , listReader .isSet ());
161+ assertEquals ("correct length at: " + i , i % 7 , ((List <?>)listReader .readObject ()).size ());
162+ } else {
163+ assertFalse ("index is not set: " + i , listReader .isSet ());
164+ assertNull ("index is not set: " + i , listReader .readObject ());
165+ }
166+ }
167+ }
129168
130169 @ Test
131170 public void listMapType () {
0 commit comments