| 68 | } |
| 69 | |
| 70 | BasicUnionBuilder::BasicUnionBuilder( |
| 71 | MemoryPool* pool, int64_t alignment, |
| 72 | const std::vector<std::shared_ptr<ArrayBuilder>>& children, |
| 73 | const std::shared_ptr<DataType>& type) |
| 74 | : ArrayBuilder(pool, alignment), |
| 75 | child_fields_(children.size()), |
| 76 | types_builder_(pool, alignment) { |
| 77 | const auto& union_type = checked_cast<const UnionType&>(*type); |
| 78 | mode_ = union_type.mode(); |
| 79 | |
| 80 | DCHECK_EQ(children.size(), union_type.type_codes().size()); |
| 81 | |
| 82 | type_codes_ = union_type.type_codes(); |
| 83 | children_ = children; |
| 84 | |
| 85 | type_id_to_child_id_.resize(union_type.max_type_code() + 1, -1); |
| 86 | type_id_to_children_.resize(union_type.max_type_code() + 1, nullptr); |
| 87 | DCHECK_LE( |
| 88 | type_id_to_children_.size() - 1, |
| 89 | static_cast<decltype(type_id_to_children_)::size_type>(UnionType::kMaxTypeCode)); |
| 90 | |
| 91 | for (size_t i = 0; i < children.size(); ++i) { |
| 92 | child_fields_[i] = union_type.field(static_cast<int>(i)); |
| 93 | |
| 94 | auto type_id = union_type.type_codes()[i]; |
| 95 | type_id_to_child_id_[type_id] = static_cast<int>(i); |
| 96 | type_id_to_children_[type_id] = children[i].get(); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | int8_t BasicUnionBuilder::AppendChild(const std::shared_ptr<ArrayBuilder>& new_child, |
| 101 | const std::string& field_name) { |