You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/07 11:38:40 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #13321: ARROW-16754: [Java] StructVector's child vectors get unexpectedly reordered after adding duplicated fields

pitrou commented on code in PR #13321:
URL: https://github.com/apache/arrow/pull/13321#discussion_r891108313


##########
java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java:
##########
@@ -171,13 +174,102 @@ public void testAddOrGetComplexChildVectors() {
       vector.addOrGetStruct("struct");
       vector.addOrGetMap("map", true);
 
-      List<FieldVector> childrens = vector.getChildrenFromFields();
-      assertEquals(5, childrens.size());
-      assertEquals(MinorType.LIST, childrens.get(0).getMinorType());
-      assertEquals(MinorType.FIXED_SIZE_LIST, childrens.get(1).getMinorType());
-      assertEquals(MinorType.UNION, childrens.get(2).getMinorType());
-      assertEquals(MinorType.STRUCT, childrens.get(3).getMinorType());
-      assertEquals(MinorType.MAP, childrens.get(4).getMinorType());
+      List<FieldVector> children = vector.getChildrenFromFields();
+      assertEquals(5, children.size());
+      assertEquals(MinorType.LIST, children.get(0).getMinorType());
+      assertEquals(MinorType.FIXED_SIZE_LIST, children.get(1).getMinorType());
+      assertEquals(MinorType.UNION, children.get(2).getMinorType());
+      assertEquals(MinorType.STRUCT, children.get(3).getMinorType());
+      assertEquals(MinorType.MAP, children.get(4).getMinorType());
     }
   }
+
+  @Test
+  public void testAddChildVectorsWithDuplicatedFieldNamesForConflictPolicyAppend() {
+    final FieldType type = new FieldType(true, Struct.INSTANCE, null, null);
+    try (StructVector vector = new StructVector("struct", allocator, type, null,
+        AbstractStructVector.ConflictPolicy.CONFLICT_APPEND, true)) {
+      final List<Field> initFields = new ArrayList<>();
+
+      // Add a bit more fields to test against stability of the internal field
+      // ordering mechanism of StructVector
+      initFields.add(Field.nullable("varchar1", MinorType.VARCHAR.getType()));
+      initFields.add(Field.nullable("int1", MinorType.INT.getType()));
+      initFields.add(Field.nullable("varchar2", MinorType.VARCHAR.getType()));
+      initFields.add(Field.nullable("int2", MinorType.INT.getType()));
+      initFields.add(Field.nullable("varchar3", MinorType.VARCHAR.getType()));
+      initFields.add(Field.nullable("int3", MinorType.INT.getType()));
+
+      // To ensure duplicated field names don't mess up the original field order
+      // in the struct vector
+      initFields.add(Field.nullable("varchar1", MinorType.VARCHAR.getType()));
+      initFields.add(Field.nullable("varchar2", MinorType.VARCHAR.getType()));
+      initFields.add(Field.nullable("varchar3", MinorType.VARCHAR.getType()));

Review Comment:
   Should we also test a duplicated field name with a different type?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org