[ 
https://issues.apache.org/jira/browse/ARROW-17530?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Apache Arrow JIRA Bot reassigned ARROW-17530:
---------------------------------------------

    Assignee:     (was: Larry White)

> [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: Bug
>          Components: Java
>    Affects Versions: 9.0.0, 9.0.1
>            Reporter: Larry White
>            Priority: Major
>
> 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)

Reply via email to