Skip to content

Commit

Permalink
apacheGH-40773: [Java] add DENSEUNION case to StructWriters, resolves
Browse files Browse the repository at this point in the history
apache#40773 (apache#40809)

### What changes are included in this PR?

Adding a `DENSEUNION` case to the `StructWriters` template so that one can create StructVectors with a DenseUnionVector child.

### Are these changes tested?

Yes

### Are there any user-facing changes?

No
* GitHub Issue: apache#40773

Authored-by: James Henderson <james@jarohen.dev>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
jarohen committed Mar 27, 2024
1 parent dc2c5c6 commit 515c61d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions java/vector/src/main/codegen/templates/StructWriters.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class ${mode}StructWriter extends AbstractFieldWriter {
map(child.getName(), arrowType.getKeysSorted());
break;
}
case DENSEUNION: {
FieldType fieldType = new FieldType(addVectorAsNullable, MinorType.DENSEUNION.getType(), null, null);
DenseUnionWriter writer = new DenseUnionWriter(container.addOrGet(child.getName(), fieldType, DenseUnionVector.class), getNullableStructWriterFactory());
fields.put(handleCase(child.getName()), writer);
break;
}
case UNION:
FieldType fieldType = new FieldType(addVectorAsNullable, MinorType.UNION.getType(), null, null);
UnionWriter writer = new UnionWriter(container.addOrGet(child.getName(), fieldType, UnionVector.class), getNullableStructWriterFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.arrow.vector.testing.ValueVectorDataPopulator;
import org.apache.arrow.vector.types.Types;
import org.apache.arrow.vector.types.Types.MinorType;
import org.apache.arrow.vector.types.UnionMode;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
Expand Down Expand Up @@ -2974,6 +2975,20 @@ public void testStructVectorEqualsWithDiffChild() {
}
}

@Test
public void testStructVectorAcceptsDenseUnionChild() {
Field childField = new Field("child",
FieldType.notNullable(new ArrowType.Union(UnionMode.Dense, new int[] {})),
Collections.emptyList());
Field structField = new Field("struct",
FieldType.notNullable(ArrowType.Struct.INSTANCE),
Collections.singletonList(childField));

try (FieldVector structVec = structField.createVector(allocator)) {
assertEquals(structField, structVec.getField());
}
}

@Test
public void testUnionVectorEquals() {
try (final UnionVector vector1 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null);
Expand Down

0 comments on commit 515c61d

Please sign in to comment.