|
34 | 34 | #include "iceberg/catalog/rest/rest_catalog.h" |
35 | 35 | #include "iceberg/catalog/rest/rest_util.h" |
36 | 36 | #include "iceberg/json_internal.h" |
| 37 | +#include "iceberg/partition_spec.h" |
37 | 38 | #include "iceberg/result.h" |
| 39 | +#include "iceberg/schema.h" |
38 | 40 | #include "iceberg/table.h" |
39 | 41 | #include "iceberg/util/macros.h" |
40 | 42 |
|
@@ -115,29 +117,67 @@ Result<std::vector<Namespace>> RestCatalog::ListNamespaces(const Namespace& ns) |
115 | 117 | } |
116 | 118 |
|
117 | 119 | Status RestCatalog::CreateNamespace( |
118 | | - [[maybe_unused]] const Namespace& ns, |
119 | | - [[maybe_unused]] const std::unordered_map<std::string, std::string>& properties) { |
120 | | - return NotImplemented("Not implemented"); |
| 120 | + const Namespace& ns, const std::unordered_map<std::string, std::string>& properties) { |
| 121 | + ICEBERG_ASSIGN_OR_RAISE(auto endpoint, paths_->Namespaces()); |
| 122 | + CreateNamespaceRequest request{.namespace_ = ns, .properties = properties}; |
| 123 | + ICEBERG_ASSIGN_OR_RAISE(auto json_request, ToJsonString(ToJson(request))); |
| 124 | + ICEBERG_ASSIGN_OR_RAISE(const auto& response, |
| 125 | + client_->Post(endpoint, json_request, /*headers=*/{}, |
| 126 | + *NamespaceErrorHandler::Instance())); |
| 127 | + ICEBERG_ASSIGN_OR_RAISE(auto json, FromJsonString(response.body())); |
| 128 | + ICEBERG_ASSIGN_OR_RAISE(auto create_response, CreateNamespaceResponseFromJson(json)); |
| 129 | + return {}; |
121 | 130 | } |
122 | 131 |
|
123 | 132 | Result<std::unordered_map<std::string, std::string>> RestCatalog::GetNamespaceProperties( |
124 | | - [[maybe_unused]] const Namespace& ns) const { |
125 | | - return NotImplemented("Not implemented"); |
126 | | -} |
127 | | - |
128 | | -Status RestCatalog::DropNamespace([[maybe_unused]] const Namespace& ns) { |
129 | | - return NotImplemented("Not implemented"); |
| 133 | + const Namespace& ns) const { |
| 134 | + ICEBERG_ASSIGN_OR_RAISE(auto endpoint, paths_->Namespace_(ns)); |
| 135 | + ICEBERG_ASSIGN_OR_RAISE(const auto& response, |
| 136 | + client_->Get(endpoint, /*params=*/{}, /*headers=*/{}, |
| 137 | + *NamespaceErrorHandler::Instance())); |
| 138 | + ICEBERG_ASSIGN_OR_RAISE(auto json, FromJsonString(response.body())); |
| 139 | + ICEBERG_ASSIGN_OR_RAISE(auto get_response, GetNamespaceResponseFromJson(json)); |
| 140 | + return get_response.properties; |
130 | 141 | } |
131 | 142 |
|
132 | | -Result<bool> RestCatalog::NamespaceExists([[maybe_unused]] const Namespace& ns) const { |
133 | | - return NotImplemented("Not implemented"); |
| 143 | +Status RestCatalog::DropNamespace(const Namespace& ns) { |
| 144 | + ICEBERG_ASSIGN_OR_RAISE(auto endpoint, paths_->Namespace_(ns)); |
| 145 | + ICEBERG_ASSIGN_OR_RAISE( |
| 146 | + const auto& response, |
| 147 | + client_->Delete(endpoint, /*headers=*/{}, *DropNamespaceErrorHandler::Instance())); |
| 148 | + return {}; |
| 149 | +} |
| 150 | + |
| 151 | +Result<bool> RestCatalog::NamespaceExists(const Namespace& ns) const { |
| 152 | + ICEBERG_ASSIGN_OR_RAISE(auto endpoint, paths_->Namespace_(ns)); |
| 153 | + auto response_or_error = |
| 154 | + client_->Head(endpoint, /*headers=*/{}, *NamespaceErrorHandler::Instance()); |
| 155 | + if (!response_or_error.has_value()) { |
| 156 | + const auto& error = response_or_error.error(); |
| 157 | + // catch NoSuchNamespaceException/404 and return false |
| 158 | + if (error.kind == ErrorKind::kNoSuchNamespace) { |
| 159 | + return false; |
| 160 | + } |
| 161 | + ICEBERG_RETURN_UNEXPECTED(response_or_error); |
| 162 | + } |
| 163 | + return true; |
134 | 164 | } |
135 | 165 |
|
136 | 166 | Status RestCatalog::UpdateNamespaceProperties( |
137 | | - [[maybe_unused]] const Namespace& ns, |
138 | | - [[maybe_unused]] const std::unordered_map<std::string, std::string>& updates, |
139 | | - [[maybe_unused]] const std::unordered_set<std::string>& removals) { |
140 | | - return NotImplemented("Not implemented"); |
| 167 | + const Namespace& ns, const std::unordered_map<std::string, std::string>& updates, |
| 168 | + const std::unordered_set<std::string>& removals) { |
| 169 | + ICEBERG_ASSIGN_OR_RAISE(auto endpoint, paths_->NamespaceProperties(ns)); |
| 170 | + UpdateNamespacePropertiesRequest request{ |
| 171 | + .removals = std::vector<std::string>(removals.begin(), removals.end()), |
| 172 | + .updates = updates}; |
| 173 | + ICEBERG_ASSIGN_OR_RAISE(auto json_request, ToJsonString(ToJson(request))); |
| 174 | + ICEBERG_ASSIGN_OR_RAISE(const auto& response, |
| 175 | + client_->Post(endpoint, json_request, /*headers=*/{}, |
| 176 | + *NamespaceErrorHandler::Instance())); |
| 177 | + ICEBERG_ASSIGN_OR_RAISE(auto json, FromJsonString(response.body())); |
| 178 | + ICEBERG_ASSIGN_OR_RAISE(auto update_response, |
| 179 | + UpdateNamespacePropertiesResponseFromJson(json)); |
| 180 | + return {}; |
141 | 181 | } |
142 | 182 |
|
143 | 183 | Result<std::vector<TableIdentifier>> RestCatalog::ListTables( |
|
0 commit comments