Skip to content

[Java] Array of Varchar example is missleading #383

@Miro-Andrin

Description

@Miro-Andrin
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.VarCharVector;

try(
    BufferAllocator allocator = new RootAllocator();
    VarCharVector varCharVector = new VarCharVector("varCharVector", allocator);
) {
    varCharVector.allocateNew(3);
    varCharVector.set(0, "one".getBytes());
    varCharVector.set(1, "two".getBytes());
    varCharVector.set(2, "three".getBytes());
    varCharVector.setValueCount(3);

    System.out.print(varCharVector);
}

This snippet only works because few short strings are written. allocateNew does not grow the data buffer depending on the size of n (3 in this case). The example should either call the allocateNew method variant that specifies the byte count, use setSafe, or have a comment about this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions