diff --git a/src/iceberg/catalog.h b/src/iceberg/catalog.h index 83ea677ab..d033199ca 100644 --- a/src/iceberg/catalog.h +++ b/src/iceberg/catalog.h @@ -161,6 +161,15 @@ class ICEBERG_EXPORT Catalog { /// - On failure, contains error information. virtual Status DropTable(const TableIdentifier& identifier, bool purge) = 0; + /// \brief Rename a table + /// + /// \param from the current table identifier + /// \param to the new table identifier + /// \return Status indicating the outcome of the operation. + /// - On success, the table was renamed. + /// - On failure, contains error information. + virtual Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) = 0; + /// \brief Load a table /// /// \param identifier a table identifier diff --git a/src/iceberg/catalog/memory/in_memory_catalog.cc b/src/iceberg/catalog/memory/in_memory_catalog.cc index c024aac20..753c3358a 100644 --- a/src/iceberg/catalog/memory/in_memory_catalog.cc +++ b/src/iceberg/catalog/memory/in_memory_catalog.cc @@ -415,6 +415,12 @@ Status InMemoryCatalog::DropTable(const TableIdentifier& identifier, bool purge) return root_namespace_->UnregisterTable(identifier); } +Status InMemoryCatalog::RenameTable(const TableIdentifier& from, + const TableIdentifier& to) { + std::unique_lock lock(mutex_); + return NotImplemented("rename table"); +} + Result> InMemoryCatalog::LoadTable( const TableIdentifier& identifier) { if (!file_io_) [[unlikely]] { diff --git a/src/iceberg/catalog/memory/in_memory_catalog.h b/src/iceberg/catalog/memory/in_memory_catalog.h index 59c6d3ad8..069a1d004 100644 --- a/src/iceberg/catalog/memory/in_memory_catalog.h +++ b/src/iceberg/catalog/memory/in_memory_catalog.h @@ -89,6 +89,8 @@ class ICEBERG_EXPORT InMemoryCatalog Status DropTable(const TableIdentifier& identifier, bool purge) override; + Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) override; + Result> LoadTable(const TableIdentifier& identifier) override; Result> RegisterTable( diff --git a/src/iceberg/table.cc b/src/iceberg/table.cc index cdcb6a95b..7c7df7c6f 100644 --- a/src/iceberg/table.cc +++ b/src/iceberg/table.cc @@ -133,6 +133,10 @@ const std::vector& Table::history() const { return metadata_->snapshot_log; } +std::unique_ptr Table::NewTransaction() const { + throw NotImplemented("Table::NewTransaction is not implemented"); +} + const std::shared_ptr& Table::io() const { return io_; } std::unique_ptr Table::NewScan() const { diff --git a/src/iceberg/table.h b/src/iceberg/table.h index f249f3d69..672cac754 100644 --- a/src/iceberg/table.h +++ b/src/iceberg/table.h @@ -109,6 +109,11 @@ class ICEBERG_EXPORT Table { /// filter data. virtual std::unique_ptr NewScan() const; + /// \brief Create a new transaction for this table + /// + /// \return a pointer to the new Transaction + virtual std::unique_ptr NewTransaction() const; + /// \brief Returns a FileIO to read and write table data and metadata files const std::shared_ptr& io() const; diff --git a/src/iceberg/test/mock_catalog.h b/src/iceberg/test/mock_catalog.h index f54982bb2..7c54ebacb 100644 --- a/src/iceberg/test/mock_catalog.h +++ b/src/iceberg/test/mock_catalog.h @@ -75,6 +75,9 @@ class MockCatalog : public Catalog { MOCK_METHOD(Status, DropTable, (const TableIdentifier&, bool), (override)); + MOCK_METHOD(Status, RenameTable, (const TableIdentifier&, const TableIdentifier&), + (override)); + MOCK_METHOD((Result>), LoadTable, (const TableIdentifier&), (override)); diff --git a/src/iceberg/transaction.h b/src/iceberg/transaction.h index 0149f329d..0bcedd6d8 100644 --- a/src/iceberg/transaction.h +++ b/src/iceberg/transaction.h @@ -21,8 +21,10 @@ #pragma once #include +#include #include "iceberg/iceberg_export.h" +#include "iceberg/result.h" #include "iceberg/type_fwd.h" namespace iceberg { @@ -44,10 +46,12 @@ class ICEBERG_EXPORT Transaction { /// \brief Apply the pending changes from all actions and commit /// - /// May throw ValidationException if any update cannot be applied to the current table - /// metadata. May throw CommitFailedException if the updates cannot be committed due to - /// conflicts. - virtual void CommitTransaction() = 0; + /// This method applies all pending data operations and metadata updates in the + /// transaction and commits them to the table in a single atomic operation. + /// + /// \return Status::OK if the transaction was committed successfully, or an error + /// status if validation failed or the commit encountered conflicts + virtual Status CommitTransaction() = 0; }; } // namespace iceberg