| 774 | explicit UnionConverter(const std::shared_ptr<DataType>& type) { type_ = type; } |
| 775 | |
| 776 | Status Init() override { |
| 777 | auto union_type = checked_cast<const UnionType*>(type_.get()); |
| 778 | mode_ = union_type->mode(); |
| 779 | type_id_to_child_num_.clear(); |
| 780 | type_id_to_child_num_.resize(union_type->max_type_code() + 1, -1); |
| 781 | int child_i = 0; |
| 782 | for (auto type_id : union_type->type_codes()) { |
| 783 | type_id_to_child_num_[type_id] = child_i++; |
| 784 | } |
| 785 | std::vector<std::shared_ptr<ArrayBuilder>> child_builders; |
| 786 | for (const auto& field : type_->fields()) { |
| 787 | std::shared_ptr<JSONConverter> child_converter; |
| 788 | RETURN_NOT_OK(GetConverter(field->type(), &child_converter)); |
| 789 | child_converters_.push_back(child_converter); |
| 790 | child_builders.push_back(child_converter->builder()); |
| 791 | } |
| 792 | if (mode_ == UnionMode::DENSE) { |
| 793 | builder_ = std::make_shared<DenseUnionBuilder>(default_memory_pool(), |
| 794 | std::move(child_builders), type_); |
| 795 | } else { |
| 796 | builder_ = std::make_shared<SparseUnionBuilder>(default_memory_pool(), |
| 797 | std::move(child_builders), type_); |
| 798 | } |
| 799 | return Status::OK(); |
| 800 | } |
| 801 | |
| 802 | // Append a JSON value that must be a 2-long array, containing the type_id |
| 803 | // and value of the UnionArray's slot. |
nothing calls this directly
no test coverage detected