lidavidm commented on code in PR #318:
URL: https://github.com/apache/arrow-cookbook/pull/318#discussion_r1308882349


##########
java/source/data.rst:
##########
@@ -23,6 +23,57 @@ Recipes related to compare, filtering or transforming data.
 
 .. contents::
 
+Append VectorSchemaRoots
+========================
+
+In some cases, VectorSchemaRoot needs to be modeled as a container. To 
accomplish
+this, you can use ``VectorSchemaRootAppender.append``. The following code gets
+the three vectors separately, and then appends the three vectors together:
+
+.. testcode::
+
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.vector.IntVector;
+    import org.apache.arrow.vector.VectorSchemaRoot;
+    import org.apache.arrow.vector.util.VectorSchemaRootAppender;
+
+    try (BufferAllocator allocator = new RootAllocator()) {
+        VectorSchemaRoot result = null;
+        IntVector appenderOne = new IntVector("column", allocator);
+        IntVector appenderTwo = new IntVector("column", allocator);
+        appenderOne.allocateNew(2);
+        appenderOne.set(0, 100);
+        appenderOne.set(1, 20);
+        appenderOne.setValueCount(2);
+        appenderTwo.allocateNew(2);
+        appenderTwo.set(0, 34);
+        appenderTwo.set(1, 75);
+        appenderTwo.setValueCount(2);
+        try (
+            final VectorSchemaRoot rootOne = new VectorSchemaRoot(
+                    Collections.singletonList(appenderOne));
+            final VectorSchemaRoot rootTwo = new VectorSchemaRoot(
+                    Collections.singletonList(appenderTwo))
+        ) {
+            if (result == null) {

Review Comment:
   result is always null...



##########
java/source/data.rst:
##########
@@ -23,6 +23,57 @@ Recipes related to compare, filtering or transforming data.
 
 .. contents::
 
+Append VectorSchemaRoots
+========================
+
+In some cases, VectorSchemaRoot needs to be modeled as a container. To 
accomplish
+this, you can use ``VectorSchemaRootAppender.append``. The following code gets
+the three vectors separately, and then appends the three vectors together:
+
+.. testcode::
+
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.vector.IntVector;
+    import org.apache.arrow.vector.VectorSchemaRoot;
+    import org.apache.arrow.vector.util.VectorSchemaRootAppender;
+
+    try (BufferAllocator allocator = new RootAllocator()) {
+        VectorSchemaRoot result = null;
+        IntVector appenderOne = new IntVector("column", allocator);
+        IntVector appenderTwo = new IntVector("column", allocator);
+        appenderOne.allocateNew(2);
+        appenderOne.set(0, 100);
+        appenderOne.set(1, 20);
+        appenderOne.setValueCount(2);
+        appenderTwo.allocateNew(2);
+        appenderTwo.set(0, 34);
+        appenderTwo.set(1, 75);
+        appenderTwo.setValueCount(2);
+        try (
+            final VectorSchemaRoot rootOne = new VectorSchemaRoot(
+                    Collections.singletonList(appenderOne));
+            final VectorSchemaRoot rootTwo = new VectorSchemaRoot(
+                    Collections.singletonList(appenderTwo))
+        ) {
+            if (result == null) {
+                result = VectorSchemaRoot.create(rootOne.getSchema(), 
allocator);
+                result.allocateNew();
+            }
+            VectorSchemaRootAppender.append(result, rootOne, rootTwo);
+            System.out.print(result.contentToTSVString());
+        }
+        result.close();

Review Comment:
   try-with-resources



##########
java/source/data.rst:
##########
@@ -23,6 +23,57 @@ Recipes related to compare, filtering or transforming data.
 
 .. contents::
 
+Append VectorSchemaRoots
+========================
+
+In some cases, VectorSchemaRoot needs to be modeled as a container. To 
accomplish
+this, you can use ``VectorSchemaRootAppender.append``. The following code gets
+the three vectors separately, and then appends the three vectors together:
+
+.. testcode::
+
+    import org.apache.arrow.memory.BufferAllocator;
+    import org.apache.arrow.memory.RootAllocator;
+    import org.apache.arrow.vector.IntVector;
+    import org.apache.arrow.vector.VectorSchemaRoot;
+    import org.apache.arrow.vector.util.VectorSchemaRootAppender;
+
+    try (BufferAllocator allocator = new RootAllocator()) {
+        VectorSchemaRoot result = null;
+        IntVector appenderOne = new IntVector("column", allocator);
+        IntVector appenderTwo = new IntVector("column", allocator);
+        appenderOne.allocateNew(2);
+        appenderOne.set(0, 100);
+        appenderOne.set(1, 20);
+        appenderOne.setValueCount(2);
+        appenderTwo.allocateNew(2);
+        appenderTwo.set(0, 34);
+        appenderTwo.set(1, 75);
+        appenderTwo.setValueCount(2);
+        try (
+            final VectorSchemaRoot rootOne = new VectorSchemaRoot(

Review Comment:
   you can just use a schema and `VectorSchemaRoot.create` to get rid of the 
nesting here by initializing everything in the top-level try-with-resources



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to