[Java] MapVector written data does not meet expectations
- Dominant language
- Java
- Stars
- 94
- Forks
- 152
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 11
Description
### What would you like help with?
```
RootAllocator allocator = new RootAllocator(Long.MAX_VALUE);
Map metadata = new HashMap<>();
metadata.put("K1", "V1");
metadata.put("K2", "V2");
Field a = new Field("key", FieldType.notNullable(new ArrowType.Int(32, true)), null);
Field b = new Field("value", FieldType.nullable(new ArrowType.Int(32,true)), null);
Schema schema = new Schema(asList(a, b), metadata);
Field struct = new Field("struct", FieldType.notNullable(new ArrowType.Struct()), schema.getFields());
StructVector structVector = new StructVector(Field.nullable("struct", struct.getType()), allocator, null);
MapVector mapVector = new MapVector(Field.nullable("map", structVector.getField().getType()), allocator, null);
mapVector.initializeChildrenFromFields(Collections.singletonList(struct));
mapVector.allocateNew();
UnionMapWriter writer = mapVector.getWriter();
for (int i = 0; i < 10; i++) {
writer.startMap();
writer.setPosition(i);
writer.key().writeInt(i);
writer.value().writeInt(i * 10);
writer.endMap();
}
writer.setValueCount(10);
```
when the types of key and value are different, data cannot be written .
Only examples of [ListVector](https://arrow.apache.org/docs/java/vector.html#building-listvector) are available in the documentation on the official website ,Please provide an example of writing data to MapVector.

Contributor guide
Research direction
Reproduce the provided Java snippet with MapVector and UnionMapWriter, then inspect the MapVector and UnionMapWriter write path for handling different key and value types. Compare the available ListVector documentation example and define completion as either successful mixed-type MapVector writes or a documented working MapVector example, backed by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100