This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-cookbook.git
The following commit(s) were added to refs/heads/main by this push:
new 0d861dc [Java] Added splicing example for IntVector (#237)
0d861dc is described below
commit 0d861dced7772e1b4f0a043a2751fd15cd190544
Author: Ash <[email protected]>
AuthorDate: Thu Aug 4 08:01:33 2022 -0700
[Java] Added splicing example for IntVector (#237)
* added splicing example
* updated content
* Update java/source/create.rst
updated per review comment
Co-authored-by: david dali susanibar arce <[email protected]>
* Update java/source/create.rst
updated per review comment
Co-authored-by: David Li <[email protected]>
* Update java/source/create.rst
update per review comment
Co-authored-by: David Li <[email protected]>
* updated per review comment
* fixed formatting
Co-authored-by: david dali susanibar arce <[email protected]>
Co-authored-by: David Li <[email protected]>
---
java/source/create.rst | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/java/source/create.rst b/java/source/create.rst
index 41fa9cb..342ee0e 100644
--- a/java/source/create.rst
+++ b/java/source/create.rst
@@ -185,6 +185,42 @@ Array of List
[[1,2,3], [10,20,30], [100,200,300], [1000,2000,3000]]
+
+Splicing
+========
+
+Splicing provides a way of copying a range of rows between two vectors of the
same type.
+
+Splicing IntVector
+------------------
+
+In this example, we copy a portion of the input IntVector to a new IntVector.
+
+.. testcode::
+
+ import org.apache.arrow.memory.BufferAllocator;
+ import org.apache.arrow.memory.RootAllocator;
+ import org.apache.arrow.vector.IntVector;
+ import org.apache.arrow.vector.util.TransferPair;
+
+ try (BufferAllocator allocator = new RootAllocator();
+ IntVector vector = new IntVector("intVector", allocator)) {
+ for (int i = 0; i < 10; i++) {
+ vector.setSafe(i, i);
+ }
+ vector.setValueCount(10);
+
+ TransferPair tp = vector.getTransferPair(allocator);
+ tp.splitAndTransfer(0, 5);
+ try (IntVector sliced = (IntVector) tp.getTo()) {
+ System.out.print(sliced);
+ }
+ }
+
+.. testoutput::
+
+ [0, 1, 2, 3, 4]
+
.. _`FieldVector`:
https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/FieldVector.html
.. _`ValueVector`: https://arrow.apache.org/docs/java/vector.html
-.. _`dictionary-encoding`:
https://arrow.apache.org/docs/format/Columnar.html#dictionary-encoded-layout
\ No newline at end of file
+.. _`dictionary-encoding`:
https://arrow.apache.org/docs/format/Columnar.html#dictionary-encoded-layout