| 89 | |
| 90 | template <typename Message> |
| 91 | Status AddExtensionSetToMessage(const ExtensionSet& ext_set, Message* message) { |
| 92 | message->clear_extension_uris(); |
| 93 | |
| 94 | std::unordered_map<std::string_view, int, ::arrow::internal::StringViewHash> map; |
| 95 | |
| 96 | auto uris = message->mutable_extension_uris(); |
| 97 | uris->Reserve(static_cast<int>(ext_set.uris().size())); |
| 98 | for (uint32_t anchor = 0; anchor < ext_set.uris().size(); ++anchor) { |
| 99 | auto uri = ext_set.uris().at(anchor); |
| 100 | if (uri.empty()) continue; |
| 101 | |
| 102 | auto ext_uri = std::make_unique<substrait::extensions::SimpleExtensionURI>(); |
| 103 | ext_uri->set_uri(std::string(uri)); |
| 104 | ext_uri->set_extension_uri_anchor(anchor); |
| 105 | uris->AddAllocated(ext_uri.release()); |
| 106 | |
| 107 | map[uri] = anchor; |
| 108 | } |
| 109 | |
| 110 | auto extensions = message->mutable_extensions(); |
| 111 | extensions->Reserve(static_cast<int>(ext_set.num_types() + ext_set.num_functions())); |
| 112 | |
| 113 | using ExtDecl = substrait::extensions::SimpleExtensionDeclaration; |
| 114 | |
| 115 | for (uint32_t anchor = 0; anchor < ext_set.num_types(); ++anchor) { |
| 116 | ARROW_ASSIGN_OR_RAISE(auto type_record, ext_set.DecodeType(anchor)); |
| 117 | if (type_record.id.empty()) continue; |
| 118 | |
| 119 | auto ext_decl = std::make_unique<ExtDecl>(); |
| 120 | |
| 121 | auto type = std::make_unique<ExtDecl::ExtensionType>(); |
| 122 | type->set_extension_uri_reference(map[type_record.id.uri]); |
| 123 | type->set_type_anchor(anchor); |
| 124 | type->set_name(std::string(type_record.id.name)); |
| 125 | ext_decl->set_allocated_extension_type(type.release()); |
| 126 | extensions->AddAllocated(ext_decl.release()); |
| 127 | } |
| 128 | |
| 129 | for (uint32_t anchor = 0; anchor < ext_set.num_functions(); ++anchor) { |
| 130 | ARROW_ASSIGN_OR_RAISE(Id function_id, ext_set.DecodeFunction(anchor)); |
| 131 | |
| 132 | auto fn = std::make_unique<ExtDecl::ExtensionFunction>(); |
| 133 | fn->set_extension_uri_reference(map[function_id.uri]); |
| 134 | fn->set_function_anchor(anchor); |
| 135 | fn->set_name(std::string(function_id.name)); |
| 136 | |
| 137 | auto ext_decl = std::make_unique<ExtDecl>(); |
| 138 | ext_decl->set_allocated_extension_function(fn.release()); |
| 139 | extensions->AddAllocated(ext_decl.release()); |
| 140 | } |
| 141 | |
| 142 | return Status::OK(); |
| 143 | } |
| 144 | |
| 145 | std::unique_ptr<substrait::Version> CreateVersion(); |
| 146 | |