This is an automated email from the ASF dual-hosted git repository.
gangwu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new e77263e feat: add rename table interface to catalog (#281)
e77263e is described below
commit e77263eb0f88002b80d61b3fd2c324f05ff5aeeb
Author: lishuxu <[email protected]>
AuthorDate: Wed Nov 12 10:20:21 2025 +0800
feat: add rename table interface to catalog (#281)
---
src/iceberg/catalog.h | 9 +++++++++
src/iceberg/catalog/memory/in_memory_catalog.cc | 6 ++++++
src/iceberg/catalog/memory/in_memory_catalog.h | 2 ++
src/iceberg/table.cc | 4 ++++
src/iceberg/table.h | 5 +++++
src/iceberg/test/mock_catalog.h | 3 +++
src/iceberg/transaction.h | 12 ++++++++----
7 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/src/iceberg/catalog.h b/src/iceberg/catalog.h
index 83ea677..d033199 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 c024aac..753c335 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<std::unique_ptr<Table>> 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 59c6d3a..069a1d0 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<std::unique_ptr<Table>> LoadTable(const TableIdentifier& identifier)
override;
Result<std::shared_ptr<Table>> RegisterTable(
diff --git a/src/iceberg/table.cc b/src/iceberg/table.cc
index cdcb6a9..7c7df7c 100644
--- a/src/iceberg/table.cc
+++ b/src/iceberg/table.cc
@@ -133,6 +133,10 @@ const std::vector<SnapshotLogEntry>& Table::history()
const {
return metadata_->snapshot_log;
}
+std::unique_ptr<Transaction> Table::NewTransaction() const {
+ throw NotImplemented("Table::NewTransaction is not implemented");
+}
+
const std::shared_ptr<FileIO>& Table::io() const { return io_; }
std::unique_ptr<TableScanBuilder> Table::NewScan() const {
diff --git a/src/iceberg/table.h b/src/iceberg/table.h
index f249f3d..672cac7 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<TableScanBuilder> NewScan() const;
+ /// \brief Create a new transaction for this table
+ ///
+ /// \return a pointer to the new Transaction
+ virtual std::unique_ptr<Transaction> NewTransaction() const;
+
/// \brief Returns a FileIO to read and write table data and metadata files
const std::shared_ptr<FileIO>& io() const;
diff --git a/src/iceberg/test/mock_catalog.h b/src/iceberg/test/mock_catalog.h
index f54982b..7c54eba 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<std::unique_ptr<Table>>), LoadTable, (const
TableIdentifier&),
(override));
diff --git a/src/iceberg/transaction.h b/src/iceberg/transaction.h
index 0149f32..0bcedd6 100644
--- a/src/iceberg/transaction.h
+++ b/src/iceberg/transaction.h
@@ -21,8 +21,10 @@
#pragma once
#include <memory>
+#include <vector>
#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