davisusanibar commented on code in PR #183:
URL: https://github.com/apache/arrow-cookbook/pull/183#discussion_r848654165
##########
java/source/create.rst:
##########
@@ -65,81 +76,38 @@ Array of List
.. testcode::
+ import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.complex.impl.UnionListWriter;
import org.apache.arrow.vector.complex.ListVector;
- RootAllocator rootAllocator = new RootAllocator(Long.MAX_VALUE);
- ListVector listVector = ListVector.empty("listVector", rootAllocator);
- UnionListWriter listWriter = listVector.getWriter();
- int[] data = new int[] { 1, 2, 3, 10, 20, 30, 100, 200, 300, 1000, 2000,
3000 };
- int tmp_index = 0;
- for(int i = 0; i < 4; i++) {
- listWriter.setPosition(i);
- listWriter.startList();
- for(int j = 0; j < 3; j++) {
- listWriter.writeInt(data[tmp_index]);
- tmp_index = tmp_index + 1;
+ try(
+ BufferAllocator allocator = new RootAllocator();
+ ListVector listVector = ListVector.empty("listVector", allocator);
+ UnionListWriter listWriter = listVector.getWriter()
+ ) {
+ int[] data = new int[] { 1, 2, 3, 10, 20, 30, 100, 200, 300, 1000,
2000, 3000 };
+ int tmp_index = 0;
+ for(int i = 0; i < 4; i++) {
+ listWriter.setPosition(i);
+ listWriter.startList();
+ for(int j = 0; j < 3; j++) {
+ listWriter.writeInt(data[tmp_index]);
+ tmp_index = tmp_index + 1;
+ }
+ listWriter.setValueCount(3);
+ listWriter.endList();
}
- listWriter.setValueCount(3);
- listWriter.endList();
- }
- listVector.setValueCount(4);
+ listVector.setValueCount(4);
- System.out.print(listVector);
+ System.out.print(listVector);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
.. testoutput::
[[1,2,3], [10,20,30], [100,200,300], [1000,2000,3000]]
-Creating VectorSchemaRoot (Table)
Review Comment:
On the description mention that these objects are one-dimensional. At
schema.rst there is a VectorSchemaRoot example also.
--
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]