-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Labels
Type: bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
The current implementation of Java VectorSchemaRoot cannot add a vector at the end of the current list (which is the generally understood meaning of "add").
The Precondition check in the method's second line prevents providing an appropriate index for adding at the end:
public VectorSchemaRoot addVector(int index, FieldVector vector) {
Preconditions.checkNotNull(vector);
Preconditions.checkArgument(index >= 0 && index < fieldVectors.size());
List<FieldVector> newVectors = new ArrayList<>();
for (int i = 0; i < fieldVectors.size(); i++) {
if (i == index) {
newVectors.add(vector);
}
newVectors.add(fieldVectors.get(i));
}
return new VectorSchemaRoot(newVectors);
}
One possible implementation resolving the issue is shown below.
public VectorSchemaRoot addVector(int index, FieldVector vector) {
Preconditions.checkNotNull(vector);
Preconditions.checkArgument(index >= 0 && index <= fieldVectors.size());
List<FieldVector> newVectors = new ArrayList<>();
if (index == fieldVectors.size()) {
newVectors.addAll(fieldVectors);
newVectors.add(vector);
} else {
for (int i = 0; i < fieldVectors.size(); i++) {
if (i == index) {
newVectors.add(vector);
}
newVectors.add(fieldVectors.get(i));
}
}
return new VectorSchemaRoot(newVectors);
}
Reporter: Larry White / @lwhite1
Note: This issue was originally created as ARROW-17530. Please see the migration documentation for further details.
jjbskir
Metadata
Metadata
Assignees
Labels
Type: bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed