You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Larry White (Jira)" <ji...@apache.org> on 2022/08/25 18:17:00 UTC

[jira] [Created] (ARROW-17530) [Java] VectorSchemaRoot#addVector() cannot add a vector to the end of the current vector collection

Larry White created ARROW-17530:
-----------------------------------

             Summary: [Java] VectorSchemaRoot#addVector() cannot add a vector to the end of the current vector collection
                 Key: ARROW-17530
                 URL: https://issues.apache.org/jira/browse/ARROW-17530
             Project: Apache Arrow
          Issue Type: Improvement
          Components: Java
    Affects Versions: 9.0.0, 9.0.1
            Reporter: Larry White
            Assignee: Larry White


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:

 
{code: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);
}
 {code}
 

 

One possible implementation resolving the issue is shown below.

 
{code: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);
}
{code}
 

 

 

 

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)