asfimport opened a new issue, #301:
URL: https://github.com/apache/arrow-java/issues/301
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:
```java
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.
```java
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](https://issues.apache.org/jira/browse/ARROW-17530) / @lwhite1
<sub>**Note**: *This issue was originally created as
[ARROW-17530](https://issues.apache.org/jira/browse/ARROW-17530). Please see
the [migration documentation](https://github.com/apache/arrow/issues/14542) for
further details.*</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]