apache / apache/arrow-cookbook

[Java] Array of Varchar example is missleading

Open
#383 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
108
Forks
49
Avg merge
2h 14m
Merged PRs (30d)
1

Description

```java
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.

Contributor guide

Open the contributing guide

Research direction

Find the Java VarCharVector example shown in the issue and read its surrounding cookbook page. Confirm the allocation behavior, then update the example to use an allocation method that specifies the byte count or setSafe, or add a warning comment; done when the example no longer implies that allocateNew(3) safely handles strings of arbitrary length.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.