2121import static org .junit .Assert .assertFalse ;
2222import static org .junit .Assert .assertTrue ;
2323
24+ import org .apache .arrow .flatbuf .Type ;
2425import org .apache .arrow .memory .BufferAllocator ;
2526import org .apache .arrow .vector .DirtyRootAllocator ;
2627import org .apache .arrow .vector .complex .AbstractMapVector ;
2728import org .apache .arrow .vector .complex .MapVector ;
2829import org .apache .arrow .vector .complex .NullableMapVector ;
2930import org .apache .arrow .vector .complex .UnionVector ;
31+ import org .apache .arrow .vector .complex .writer .BaseWriter .MapWriter ;
3032import org .apache .arrow .vector .types .Types .MinorType ;
33+ import org .apache .arrow .vector .types .pojo .Field ;
3134import org .junit .After ;
3235import org .junit .Before ;
3336import org .junit .Test ;
@@ -50,7 +53,7 @@ public void terminate() throws Exception {
5053 @ Test
5154 public void testPromoteToUnion () throws Exception {
5255
53- try (final AbstractMapVector container = new MapVector (EMPTY_SCHEMA_PATH , allocator , null );
56+ try (final MapVector container = new MapVector (EMPTY_SCHEMA_PATH , allocator , null );
5457 final NullableMapVector v = container .addOrGet ("test" , MinorType .MAP , NullableMapVector .class );
5558 final PromotableWriter writer = new PromotableWriter (v , container )) {
5659
@@ -92,6 +95,22 @@ public void testPromoteToUnion() throws Exception {
9295
9396 assertFalse ("4 shouldn't be null" , accessor .isNull (4 ));
9497 assertEquals (100 , accessor .getObject (4 ));
98+
99+ container .clear ();
100+ container .allocateNew ();
101+
102+ ComplexWriterImpl newWriter = new ComplexWriterImpl (EMPTY_SCHEMA_PATH , container );
103+
104+ MapWriter newMapWriter = newWriter .rootAsMap ();
105+
106+ newMapWriter .start ();
107+
108+ newMapWriter .setPosition (2 );
109+ newMapWriter .integer ("A" ).writeInt (10 );
110+
111+ Field childField = container .getField ().getChildren ().get (0 ).getChildren ().get (0 );
112+ assertEquals ("Child field should be union type: " + childField .getName (), Type .Union , childField .getType ().getTypeType ());
113+
95114 }
96115 }
97116}
0 commit comments