amol- commented on a change in pull request #131:
URL: https://github.com/apache/arrow-cookbook/pull/131#discussion_r797512813
##########
File path: java/source/create.rst
##########
@@ -30,8 +30,128 @@ Array of Int (32-bit integer value)
intVector.set(2, 3);
intVector.setValueCount(3);
- System.out.println(intVector);
+ System.out.print(intVector);
.. testoutput::
- [1, 2, 3]
\ No newline at end of file
+ [1, 2, 3]
+
+
+Array of Varchar
+----------------
+
+.. testcode::
+
+ import org.apache.arrow.vector.VarCharVector;
+ import org.apache.arrow.memory.RootAllocator;
+
+ RootAllocator rootAllocator = new RootAllocator(Long.MAX_VALUE);
+
+ VarCharVector varVector = new VarCharVector("varVector", rootAllocator);
+ varVector.allocateNew(3);
+ varVector.set(0, "one".getBytes());
+ varVector.set(1, "two".getBytes());
+ varVector.set(2, "three".getBytes());
+ varVector.setValueCount(3);
+
+ System.out.print(varVector);
+
+.. testoutput::
+
+ [one, two, three]
+
+Array of List
+-------------
+
+.. testcode::
+
+ import org.apache.arrow.memory.RootAllocator;
+ import org.apache.arrow.vector.complex.impl.UnionListWriter;
+ import org.apache.arrow.vector.types.Types.MinorType;
+ import org.apache.arrow.vector.types.pojo.FieldType;
+ import org.apache.arrow.vector.complex.ListVector;
+
+ RootAllocator rootAllocator = new RootAllocator(Long.MAX_VALUE);
+
+ ListVector listVector = ListVector.empty("listVector", rootAllocator);
+ listVector.allocateNew();
+ MinorType type = MinorType.INT;
+ listVector.addOrGetVector(FieldType.nullable(type.getType()));
+ UnionListWriter listWriter = listVector.getWriter();
+ listWriter.allocate();
+ listWriter.setPosition(0);
+ listWriter.startList();
+ listWriter.bigInt().writeBigInt(1);
+ listWriter.bigInt().writeBigInt(2);
+ listWriter.bigInt().writeBigInt(3);
+ listWriter.endList();
+ listWriter.setPosition(1);
+ listWriter.startList();
+ listWriter.bigInt().writeBigInt(9);
+ listWriter.bigInt().writeBigInt(8);
+ listWriter.endList();
+ listWriter.setPosition(2);
+ listWriter.startList();
+ listWriter.bigInt().writeBigInt(10);
+ listWriter.bigInt().writeBigInt(20);
+ listWriter.bigInt().writeBigInt(30);
+ listWriter.endList();
Review comment:
Given that this is mostly a repetition of `setPosition, startList,
ADD_DATA, endList` I wonder if we can make it a loop. If we simplify ADD_DATA
to be always 3 numbers, we could easily store the numbers in an array and just
loop over it.
Something like
```
int[] data = new int[] { 1, 2, 3, 9, 8, 7, 10, 20, 30 };
for(int i = 0; i < 3; i++) {
listWriter.setPosition(i);
listWriter.startList();
for(int j = 0; j < 3; j++) {
listWriter.writeInt(data[(i+1)*j]);
}
listWriter.endList();
}
```
--
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]