4242#include " iceberg/schema.h"
4343#include " iceberg/sort_order.h"
4444#include " iceberg/table.h"
45+ #include " iceberg/table_requirement.h"
46+ #include " iceberg/table_update.h"
4547#include " iceberg/util/macros.h"
4648
4749namespace iceberg ::rest {
@@ -177,7 +179,7 @@ Result<std::vector<Namespace>> RestCatalog::ListNamespaces(const Namespace& ns)
177179 if (list_response.next_page_token .empty ()) {
178180 return result;
179181 }
180- next_token = list_response.next_page_token ;
182+ next_token = std::move ( list_response.next_page_token ) ;
181183 }
182184 return result;
183185}
@@ -246,9 +248,30 @@ Status RestCatalog::UpdateNamespaceProperties(
246248 return {};
247249}
248250
249- Result<std::vector<TableIdentifier>> RestCatalog::ListTables (
250- [[maybe_unused]] const Namespace& ns) const {
251- return NotImplemented (" Not implemented" );
251+ Result<std::vector<TableIdentifier>> RestCatalog::ListTables (const Namespace& ns) const {
252+ ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::ListTables ());
253+
254+ ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Tables (ns));
255+ std::vector<TableIdentifier> result;
256+ std::string next_token;
257+ while (true ) {
258+ std::unordered_map<std::string, std::string> params;
259+ if (!next_token.empty ()) {
260+ params[kQueryParamPageToken ] = next_token;
261+ }
262+ ICEBERG_ASSIGN_OR_RAISE (
263+ const auto response,
264+ client_->Get (path, params, /* headers=*/ {}, *TableErrorHandler::Instance ()));
265+ ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (response.body ()));
266+ ICEBERG_ASSIGN_OR_RAISE (auto list_response, ListTablesResponseFromJson (json));
267+ result.insert (result.end (), list_response.identifiers .begin (),
268+ list_response.identifiers .end ());
269+ if (list_response.next_page_token .empty ()) {
270+ return result;
271+ }
272+ next_token = std::move (list_response.next_page_token );
273+ }
274+ return result;
252275}
253276
254277Result<std::shared_ptr<Table>> RestCatalog::CreateTable (
@@ -282,10 +305,33 @@ Result<std::shared_ptr<Table>> RestCatalog::CreateTable(
282305}
283306
284307Result<std::shared_ptr<Table>> RestCatalog::UpdateTable (
285- [[maybe_unused]] const TableIdentifier& identifier,
286- [[maybe_unused]] const std::vector<std::unique_ptr<TableRequirement>>& requirements,
287- [[maybe_unused]] const std::vector<std::unique_ptr<TableUpdate>>& updates) {
288- return NotImplemented (" Not implemented" );
308+ const TableIdentifier& identifier,
309+ const std::vector<std::unique_ptr<TableRequirement>>& requirements,
310+ const std::vector<std::unique_ptr<TableUpdate>>& updates) {
311+ ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::UpdateTable ());
312+ ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Table (identifier));
313+
314+ CommitTableRequest request{.identifier = identifier};
315+ request.requirements .reserve (requirements.size ());
316+ for (const auto & req : requirements) {
317+ request.requirements .push_back (req->Clone ());
318+ }
319+ request.updates .reserve (updates.size ());
320+ for (const auto & update : updates) {
321+ request.updates .push_back (update->Clone ());
322+ }
323+
324+ ICEBERG_ASSIGN_OR_RAISE (auto json_request, ToJsonString (ToJson (request)));
325+ ICEBERG_ASSIGN_OR_RAISE (
326+ const auto response,
327+ client_->Post (path, json_request, /* headers=*/ {}, *TableErrorHandler::Instance ()));
328+
329+ ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (response.body ()));
330+ ICEBERG_ASSIGN_OR_RAISE (auto commit_response, CommitTableResponseFromJson (json));
331+
332+ return Table::Make (identifier, std::move (commit_response.metadata ),
333+ std::move (commit_response.metadata_location ), file_io_,
334+ shared_from_this ());
289335}
290336
291337Result<std::shared_ptr<Transaction>> RestCatalog::StageCreateTable (
@@ -323,9 +369,17 @@ Result<bool> RestCatalog::TableExists(const TableIdentifier& identifier) const {
323369 client_->Head (path, /* headers=*/ {}, *TableErrorHandler::Instance ()));
324370}
325371
326- Status RestCatalog::RenameTable ([[maybe_unused]] const TableIdentifier& from,
327- [[maybe_unused]] const TableIdentifier& to) {
328- return NotImplemented (" Not implemented" );
372+ Status RestCatalog::RenameTable (const TableIdentifier& from, const TableIdentifier& to) {
373+ ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::RenameTable ());
374+ ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Rename ());
375+
376+ RenameTableRequest request{.source = from, .destination = to};
377+ ICEBERG_ASSIGN_OR_RAISE (auto json_request, ToJsonString (ToJson (request)));
378+ ICEBERG_ASSIGN_OR_RAISE (
379+ const auto response,
380+ client_->Post (path, json_request, /* headers=*/ {}, *TableErrorHandler::Instance ()));
381+
382+ return {};
329383}
330384
331385Result<std::string> RestCatalog::LoadTableInternal (
@@ -352,9 +406,25 @@ Result<std::shared_ptr<Table>> RestCatalog::LoadTable(const TableIdentifier& ide
352406}
353407
354408Result<std::shared_ptr<Table>> RestCatalog::RegisterTable (
355- [[maybe_unused]] const TableIdentifier& identifier,
356- [[maybe_unused]] const std::string& metadata_file_location) {
357- return NotImplemented (" Not implemented" );
409+ const TableIdentifier& identifier, const std::string& metadata_file_location) {
410+ ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::RegisterTable ());
411+ ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Register (identifier.ns ));
412+
413+ RegisterTableRequest request{
414+ .name = identifier.name ,
415+ .metadata_location = metadata_file_location,
416+ };
417+
418+ ICEBERG_ASSIGN_OR_RAISE (auto json_request, ToJsonString (ToJson (request)));
419+ ICEBERG_ASSIGN_OR_RAISE (
420+ const auto response,
421+ client_->Post (path, json_request, /* headers=*/ {}, *TableErrorHandler::Instance ()));
422+
423+ ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (response.body ()));
424+ ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFromJson (json));
425+ return Table::Make (identifier, std::move (load_result.metadata ),
426+ std::move (load_result.metadata_location ), file_io_,
427+ shared_from_this ());
358428}
359429
360430} // namespace iceberg::rest
0 commit comments