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