@@ -27,7 +27,7 @@ Concatenate VectorSchemaRoots
2727=============================
2828
2929In some cases, VectorSchemaRoot needs to be modeled as a container. To accomplish
30- this, you can use ``VectorSchemaRootAppender.append ``. The following code
30+ this, you can use ``VectorSchemaRootAppender.append ``. The following code
3131creates two roots, then concatenates them together:
3232
3333.. testcode ::
@@ -75,6 +75,46 @@ creates two roots, then concatenates them together:
7575 34
7676 75
7777
78+ Concatenate Value Vectors
79+ =========================
80+
81+ In some cases, we need to concatenate two value vectors into one. To accomplish
82+ this, we can use `VectorAppender `_. This mutates the initial ValueVector.
83+
84+ .. testcode ::
85+
86+ import org.apache.arrow.memory.BufferAllocator;
87+ import org.apache.arrow.memory.RootAllocator;
88+ import org.apache.arrow.vector.IntVector;
89+ import org.apache.arrow.vector.ValueVector;
90+ import org.apache.arrow.vector.util.VectorAppender;
91+
92+ try (
93+ BufferAllocator allocator = new RootAllocator();
94+ IntVector initialValues = new IntVector("initialValues", allocator);
95+ IntVector toAppend = new IntVector("toAppend", allocator);
96+ ) {
97+ initialValues.allocateNew(2);
98+ initialValues.set(0, 1);
99+ initialValues.set(1, 2);
100+ initialValues.setValueCount(2);
101+ System.out.println("Initial IntVector: " + initialValues);
102+ toAppend.allocateNew(4);
103+ toAppend.set(1, 4);
104+ toAppend.set(3, 6);
105+ toAppend.setValueCount(4);
106+ System.out.println("IntVector to Append: " + toAppend);
107+ VectorAppender appenderUtil = new VectorAppender(initialValues);
108+ toAppend.accept(appenderUtil, null);
109+ System.out.println("IntVector Result: " + initialValues);
110+ }
111+
112+ .. testoutput ::
113+
114+ Initial IntVector: [1, 2]
115+ IntVector to Append: [null, 4, null, 6]
116+ IntVector Result: [1, 2, null, 4, null, 6]
117+
78118Compare Vectors for Field Equality
79119==================================
80120
@@ -331,3 +371,5 @@ FixedWidthOutOfPlaceVectorSorter & VariableWidthOutOfPlaceVectorSor
331371.. testoutput ::
332372
333373 [null, 8, 10]
374+
375+ .. _`VectorAppender` : https://github.com/apache/arrow/blob/main/java/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java
0 commit comments