Skip to content

[Java] VectorSchemaRoot#addVector() cannot add a vector to the end of the current vector collection #301

Closed

Description

@asfimport

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.

Activity

  1. asfimport commented on Nov 24, 2022

    @asfimport
    Author

    Apache Arrow JIRA Bot:
    This issue was last updated over 90 days ago, which may be an indication it is no longer being actively worked. To better reflect the current state, the issue is being unassigned per project policy. Please feel free to re-take assignment of the issue if it is being actively worked, or if you plan to start that work soon.

  2. transferred this issue fromapache/arrowon Nov 26, 2024
  3. jjbskir commented on Apr 22, 2025

    @jjbskir

    Hey, I noticed the same issue recently on this line of code as well. Is this expected behavior? If I have an existing VectorSchemaRoot and want to add a new FieldVector to it is there a better way to do it?

    Happy to put up a CR to address the issue as well.

  4. lidavidm commented on Apr 22, 2025

    @lidavidm
    Member

    I suppose you can always create a new root, but given the existence of the method I would support fixing this too. PRs are welcome.

  5. jjbskir commented on Apr 28, 2025

    @jjbskir

    Sounds good! Will look into putting up a PR for this.

  6. added 2 commits that reference this issue on Feb 8, 2026
  7. added this to the 19.0.0 milestone on Feb 8, 2026
  8. added 2 commits that reference this issue on Feb 16, 2026
  9. added a commit that references this issue on Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions