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 ;
@@ -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