Skip to content

Commit 10be298

Browse files
GH-319: [Java] recipe to concatenate value vectors as one (#320)
Closes #319. --------- Co-authored-by: David Li <[email protected]>
1 parent 1c9a3f4 commit 10be298

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

java/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
author = 'The Apache Software Foundation'
3939
arrow_nightly=os.getenv("ARROW_NIGHTLY")
4040
if arrow_nightly and arrow_nightly != '0':
41-
version = "13.0.0-SNAPSHOT"
41+
version = "14.0.0-SNAPSHOT"
4242
else:
43-
version = "12.0.0"
43+
version = "13.0.0"
4444
print(f"Running with Arrow version: {version}")
4545

4646
# -- General configuration ---------------------------------------------------

java/source/data.rst

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Concatenate VectorSchemaRoots
2727
=============================
2828

2929
In 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
3131
creates 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+
78118
Compare 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

Comments
 (0)