You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "i10416 (via GitHub)" <gi...@apache.org> on 2023/05/15 03:57:43 UTC

[GitHub] [arrow] i10416 opened a new issue, #35585: Java: What is the best way to concat two vector?

i10416 opened a new issue, #35585:
URL: https://github.com/apache/arrow/issues/35585

   ### Describe the usage question you have. Please include as many useful details as  possible.
   
   
   Given two `IntVector`s `one: {1, 2, 3}` and `another: {null, 5, 6}`, 
   how can I concat them into avector `result: {1, 2, 3, 4, 5, 6}`?
   
   
   Should I copy element one by one using `copyFromSafe` or is there any convenient method to achieve the same result?
   
   If I should copy element one by one, how can I calculate value count and null count of the result?
   
   ```scala
   val one : IntVector = ??? // suppose {1, 2, 3,}
   val another: IntVector = ??? // suppose {null, 5, 6}
   
   val offset = one.getValueCount() +one.getNullCount() // 3
   val len = another.getValueCount() + another.getNullCount() // 3
   var i = 0
   while i < len do
       one.copyFromSafe(i, offset + i, another) 
       // can I detect whether copied value is null here so that I can respectively count non-null value and null value?
       // for example
       // val isNull = one.nullAwareCopyFromSafe(i, offset + i, another) 
       // if isNull then j += 1 else i += 1
       i += 1
   one.setValueCount(offset + i) 
   // offset + i is 6, but another may contain null, so value count could be different from actual value.
   ```
   
   
   
   
   ### Component(s)
   
   Java


-- 
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: issues-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on issue #35585: Java: What is the best way to concat two vectors?

Posted by "davisusanibar (via GitHub)" <gi...@apache.org>.
davisusanibar commented on issue #35585:
URL: https://github.com/apache/arrow/issues/35585#issuecomment-1683045712

   Hi @i10416, sorry to join late,
   
   There is a [VectorAppender](https://github.com/apache/arrow/blob/main/java/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java) class with some util methods, main problem it is private-package.
   
   Class inside custom package:
   ```java
       package org.apache.arrow.vector.util;
   
       import org.apache.arrow.memory.BufferAllocator;
       import org.apache.arrow.memory.RootAllocator;
       import org.apache.arrow.vector.IntVector;
       import org.apache.arrow.vector.ValueVector;
   
       public class FieldVectorAppender {
         public static void main(String[] args) {
           try (
               BufferAllocator allocator = new RootAllocator();
               IntVector initialValues = new IntVector("initialValues", allocator);
               IntVector toAppend = new IntVector("toAppend", allocator);
           ) {
             initialValues.allocateNew(2);
             initialValues.set(0, 1);
             initialValues.set(1, 2);
             initialValues.setValueCount(2);
             System.out.println("Initial IntVector: " + initialValues);
             toAppend.allocateNew(4);
             toAppend.set(1, 4);
             toAppend.set(3, 6);
             toAppend.setValueCount(4);
             System.out.println("IntVector to Append: " + toAppend);
             VectorAppender appenderUtil = new VectorAppender(initialValues);
             ValueVector resultOfVectorsAppended = toAppend.accept(appenderUtil, null);
             System.out.println("IntVector Result: " + resultOfVectorsAppended);
           }
         }
       }
   ```
   
   Test:
   ```shell
       Initial IntVector: [1, 2]
       IntVector to Append: [null, 4, null, 6]
       IntVector Result: [1, 2, null, 4, null, 6]
   ```
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on issue #35585: Java: What is the best way to concat two vector?

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on issue #35585:
URL: https://github.com/apache/arrow/issues/35585#issuecomment-1547835508

   @davisusanibar do we have a recipe for this?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org