liyafan82 commented on a change in pull request #8363:
URL: https://github.com/apache/arrow/pull/8363#discussion_r503178275



##########
File path: 
java/vector/src/test/java/org/apache/arrow/vector/testing/ValueVectorDataPopulator.java
##########
@@ -673,4 +677,32 @@ public static void setVector(FixedSizeListVector vector, 
List<Integer>... values
     dataVector.setValueCount(curPos);
     vector.setValueCount(values.length);
   }
+
+  /**
+   * Populate values for {@link StructVector}.
+   */
+  public static void setVector(StructVector vector, Map<String, List<Integer>> 
values) {
+    vector.allocateNewSafe();
+
+    int valueCount = 0;
+    for (final Entry<String, List<Integer>> entry : values.entrySet()) {
+      // Add the child
+      final IntVector child = vector.addOrGet(entry.getKey(),
+          FieldType.nullable(MinorType.INT.getType()), IntVector.class);
+
+      // Write the values to the child
+      child.allocateNew();
+      final List<Integer> v = entry.getValue();
+      for (int i = 0; i < v.size(); i++) {
+        if (v.get(i) != null) {
+          child.set(i, v.get(i));
+        } else {
+          child.setNull(i);
+        }
+        vector.setIndexDefined(i);

Review comment:
       For a StructVector, we can set an element to null. For its super class 
(NonNullableStructVector), we cannot set an element to null. 
   
   Here, I generally prefer setting an element to null if all sub-elements are 
null, because ValueVectorDataPopulator is a generally-purpose class, and we may 
use it to test scenarios with null elements. 




----------------------------------------------------------------
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.

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


Reply via email to