Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ public ValueVector getVectorById(int id) {
return getChildByOrdinal(id);
}

/**
* Gets a child vector by ordinal position and casts to the specified class.
*/
public <V extends ValueVector> V getVectorById(int id, Class<V> clazz) {
ValueVector untyped = getVectorById(id);
if (clazz.isInstance(untyped)) {
return clazz.cast(untyped);
}
throw new ClassCastException("Id " + id + " had the wrong type. Expected " + clazz.getCanonicalName() +
" but was " + untyped.getClass().getCanonicalName());
}

@Override
public void setValueCount(int valueCount) {
for (final ValueVector v : getChildren()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,12 @@ public void testAddChildVectorsWithDuplicatedFieldNamesForConflictPolicyReplace(
}
}

@Test
public void testTypedGetters() {
try (final StructVector s1 = StructVector.empty("s1", allocator)) {
s1.addOrGet("struct_child", FieldType.nullable(MinorType.INT.getType()), IntVector.class);
assertEquals(IntVector.class, s1.getChild("struct_child", IntVector.class).getClass());
assertEquals(IntVector.class, s1.getVectorById(0, IntVector.class).getClass());
}
}
}