Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions java/vector/src/main/codegen/templates/MapWriters.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
}
</#if>
this.container = container;
for (Field child : container.getField().getChildren()) {
switch (Types.getMinorTypeForArrowType(child.getType())) {
case MAP:
map(child.getName());
break;
case LIST:
list(child.getName());
break;
case UNION:
UnionWriter writer = new UnionWriter(container.addOrGet(child.getName(), MinorType.UNION, UnionVector.class));
fields.put(child.getName().toLowerCase(), writer);
break;
<#list vv.types as type><#list type.minor as minor>
<#assign lowerName = minor.class?uncap_first />
<#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
<#assign upperName = minor.class?upper_case />
case ${upperName}:
${lowerName}(child.getName());
break;
</#list></#list>
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.apache.arrow.flatbuf.Type;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.DirtyRootAllocator;
import org.apache.arrow.vector.complex.AbstractMapVector;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void terminate() throws Exception {
@Test
public void testPromoteToUnion() throws Exception {

try (final AbstractMapVector container = new MapVector(EMPTY_SCHEMA_PATH, allocator, null);
try (final MapVector container = new MapVector(EMPTY_SCHEMA_PATH, allocator, null);
final NullableMapVector v = container.addOrGet("test", MinorType.MAP, NullableMapVector.class);
final PromotableWriter writer = new PromotableWriter(v, container)) {

Expand Down Expand Up @@ -92,6 +93,19 @@ public void testPromoteToUnion() throws Exception {

assertFalse("4 shouldn't be null", accessor.isNull(4));
assertEquals(100, accessor.getObject(4));

container.clear();
container.allocateNew();

ComplexWriterImpl newWriter = new ComplexWriterImpl(EMPTY_SCHEMA_PATH, container);

writer.start();

writer.setPosition(2);
writer.integer("A").writeInt(10);

assertEquals("Child field should be union type", Type.Union, container.getField().getChildren().get(0).getChildren().get(0).getType().getTypeType());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having the field itself in the message makes it much easier to understand the failure:
Field child = container.getField().getChildren().get(0).getChildren().get(0)
assertEquals("Child field should be union type: " + child, Type.Union, child.getType().getTypeType());


}
}
}