Open i10416 opened 1 year ago
@davisusanibar do we have a recipe for this?
Hi @i10416, sorry to join late,
There is a VectorAppender class with some util methods, main problem it is private-package.
Class inside custom package:
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:
Initial IntVector: [1, 2]
IntVector to Append: [null, 4, null, 6]
IntVector Result: [1, 2, null, 4, null, 6]
Describe the usage question you have. Please include as many useful details as possible.
Given two
IntVector
sone: {1, 2, 3}
andanother: {null, 5, 6}
, how can I concat them into avectorresult: {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?
Component(s)
Java