| 826 | explicit UnionConverter(const std::shared_ptr<DataType>& type) { type_ = type; } |
| 827 | |
| 828 | Status Init() override { |
| 829 | auto union_type = checked_cast<const UnionType*>(type_.get()); |
| 830 | mode_ = union_type->mode(); |
| 831 | type_id_to_child_num_.clear(); |
| 832 | type_id_to_child_num_.resize(union_type->max_type_code() + 1, -1); |
| 833 | int child_i = 0; |
| 834 | for (auto type_id : union_type->type_codes()) { |
| 835 | type_id_to_child_num_[type_id] = child_i++; |
| 836 | } |
| 837 | std::vector<std::shared_ptr<ArrayBuilder>> child_builders; |
| 838 | for (const auto& field : type_->fields()) { |
| 839 | std::shared_ptr<JSONConverter> child_converter; |
| 840 | RETURN_NOT_OK(GetConverter(field->type(), &child_converter)); |
| 841 | child_converters_.push_back(child_converter); |
| 842 | child_builders.push_back(child_converter->builder()); |
| 843 | } |
| 844 | if (mode_ == UnionMode::DENSE) { |
| 845 | builder_ = std::make_shared<DenseUnionBuilder>(default_memory_pool(), |
| 846 | std::move(child_builders), type_); |
| 847 | } else { |
| 848 | builder_ = std::make_shared<SparseUnionBuilder>(default_memory_pool(), |
| 849 | std::move(child_builders), type_); |
| 850 | } |
| 851 | return Status::OK(); |
| 852 | } |
| 853 | |
| 854 | // Append a JSON value that must be a 2-long array, containing the type_id |
| 855 | // and value of the UnionArray's slot. |
nothing calls this directly
no test coverage detected