Skip to content

Deep copy a VectorSchemaRoot? #465

@tisonkun

Description

@tisonkun

Describe the enhancement requested

I'm writing a convertor method to convert a base64 encoded byte array into Arrow batches and returns it to the user.

public List<VectorSchemaRoot> readArrowBatches(String rows, BufferAllocator allocator) {
    final List<VectorSchemaRoot> batches = new ArrayList<>();
    final byte[] data = Base64.getDecoder().decode(rows);
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    try (final ArrowStreamReader reader = new ArrowStreamReader(stream, allocator)) {
        while (reader.loadNextBatch()) {
            batches.add(new Table(reader.getVectorSchemaRoot()).toVectorSchemaRoot());
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return batches;
}

Since ArrowStreamReader replace the batch referred by getVectorSchemaRoot in each iteration, I have to do a deepcopy of VectorSchemaRoot every time.

Currently, I use Table's method as a workaround, but wonder if VectorSchemaRoot deserves a copy method, or I implement such a typically use case in a wrong way.

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