Skip to content

[Java] MapVector written data does not meet expectations #40

Open

Description

@hawk9821

What would you like help with?

    RootAllocator allocator = new RootAllocator(Long.MAX_VALUE);
    Map<String, String> 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 are available in the documentation on the official website ,Please provide an example of writing data to MapVector.

image

Activity

  1. changed the title [-][Java] MapVector write demo[/-] [+][Java] MapVector written data does not meet expectations[/+] on Nov 6, 2024
  2. lidavidm commented on Nov 6, 2024

    @lidavidm
    Member

    I think this belongs on apache/arrow and not apache/arrow-adbc?

  3. transferred this issue fromapache/arrow-adbcon Nov 6, 2024
  4. hawk9821 commented on Nov 7, 2024

    @hawk9821
    Author

    I think this belongs on apache/arrow and not apache/arrow-adbc?

    yes , here are the dependencies , version is 15.0.1

            <dependency>
                <groupId>org.apache.arrow</groupId>
                <artifactId>arrow-vector</artifactId>
                <version>${arrow.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.arrow</groupId>
                <artifactId>arrow-memory-netty</artifactId>
                <version>${arrow.version}</version>
            </dependency>
    
  5. hawk9821 commented on Nov 12, 2024

    @hawk9821
    Author

    @lidavidm hi, whether the community has a plan to provide the correct MapVector example

  6. lidavidm commented on Nov 25, 2024

    @lidavidm
    Member

    @hawk9821 sorry for the delay, if I can find some time I will try to add a Cookbook example

  7. transferred this issue fromapache/arrowon Nov 26, 2024
  8. yashdotdev13 commented on Nov 14, 2026

    @yashdotdev13

    Hi @lidavidm,

    I've opened PR #1475 with a MapVector usage example.

    The example demonstrates creating a MapVector with BIGINT keys and INT values, writing multiple key-value entries using UnionMapWriter, and reading them back using UnionMapReader.

    I hope this helps clarify the expected usage of MapVector. Feedback and suggestions are welcome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions