use of org.apache.drill.exec.vector.complex.UnionVector in project drill by apache.
the class SchemaUtil method coerceVector.
private static ValueVector coerceVector(ValueVector v, VectorContainer c, MaterializedField field, int recordCount, BufferAllocator allocator) {
if (v != null) {
int valueCount = v.getAccessor().getValueCount();
TransferPair tp = v.getTransferPair(allocator);
tp.transfer();
if (v.getField().getType().getMinorType().equals(field.getType().getMinorType())) {
if (field.getType().getMinorType() == MinorType.UNION) {
UnionVector u = (UnionVector) tp.getTo();
for (MinorType t : field.getType().getSubTypeList()) {
u.addSubType(t);
}
}
return tp.getTo();
} else {
ValueVector newVector = TypeHelper.getNewVector(field, allocator);
Preconditions.checkState(field.getType().getMinorType() == MinorType.UNION, "Can only convert vector to Union vector");
UnionVector u = (UnionVector) newVector;
u.setFirstType(tp.getTo(), valueCount);
return u;
}
} else {
v = TypeHelper.getNewVector(field, allocator);
v.allocateNew();
v.getMutator().setValueCount(recordCount);
return v;
}
}
Aggregations