HedgehogCode commented on a change in pull request #8363:
URL: https://github.com/apache/arrow/pull/8363#discussion_r503126829
##########
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:
I am not sure.
The current implementation does not allow setting any struct element to
`null`. If we only call `#setIndexDefined` if the child element is not `null`
the implementation would not allow (non null) structs with all child values
beeing `null`. I am okay with both but I think we should keep the API simple
because this method is just there to make tests shorter.
----------------------------------------------------------------
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]