Skip to content

Commit e77263e

Browse files
authored
feat: add rename table interface to catalog (#281)
1 parent 8388f32 commit e77263e

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

src/iceberg/catalog.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ class ICEBERG_EXPORT Catalog {
161161
/// - On failure, contains error information.
162162
virtual Status DropTable(const TableIdentifier& identifier, bool purge) = 0;
163163

164+
/// \brief Rename a table
165+
///
166+
/// \param from the current table identifier
167+
/// \param to the new table identifier
168+
/// \return Status indicating the outcome of the operation.
169+
/// - On success, the table was renamed.
170+
/// - On failure, contains error information.
171+
virtual Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) = 0;
172+
164173
/// \brief Load a table
165174
///
166175
/// \param identifier a table identifier

src/iceberg/catalog/memory/in_memory_catalog.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ Status InMemoryCatalog::DropTable(const TableIdentifier& identifier, bool purge)
415415
return root_namespace_->UnregisterTable(identifier);
416416
}
417417

418+
Status InMemoryCatalog::RenameTable(const TableIdentifier& from,
419+
const TableIdentifier& to) {
420+
std::unique_lock lock(mutex_);
421+
return NotImplemented("rename table");
422+
}
423+
418424
Result<std::unique_ptr<Table>> InMemoryCatalog::LoadTable(
419425
const TableIdentifier& identifier) {
420426
if (!file_io_) [[unlikely]] {

src/iceberg/catalog/memory/in_memory_catalog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class ICEBERG_EXPORT InMemoryCatalog
8989

9090
Status DropTable(const TableIdentifier& identifier, bool purge) override;
9191

92+
Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) override;
93+
9294
Result<std::unique_ptr<Table>> LoadTable(const TableIdentifier& identifier) override;
9395

9496
Result<std::shared_ptr<Table>> RegisterTable(

src/iceberg/table.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ const std::vector<SnapshotLogEntry>& Table::history() const {
133133
return metadata_->snapshot_log;
134134
}
135135

136+
std::unique_ptr<Transaction> Table::NewTransaction() const {
137+
throw NotImplemented("Table::NewTransaction is not implemented");
138+
}
139+
136140
const std::shared_ptr<FileIO>& Table::io() const { return io_; }
137141

138142
std::unique_ptr<TableScanBuilder> Table::NewScan() const {

src/iceberg/table.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ class ICEBERG_EXPORT Table {
109109
/// filter data.
110110
virtual std::unique_ptr<TableScanBuilder> NewScan() const;
111111

112+
/// \brief Create a new transaction for this table
113+
///
114+
/// \return a pointer to the new Transaction
115+
virtual std::unique_ptr<Transaction> NewTransaction() const;
116+
112117
/// \brief Returns a FileIO to read and write table data and metadata files
113118
const std::shared_ptr<FileIO>& io() const;
114119

src/iceberg/test/mock_catalog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class MockCatalog : public Catalog {
7575

7676
MOCK_METHOD(Status, DropTable, (const TableIdentifier&, bool), (override));
7777

78+
MOCK_METHOD(Status, RenameTable, (const TableIdentifier&, const TableIdentifier&),
79+
(override));
80+
7881
MOCK_METHOD((Result<std::unique_ptr<Table>>), LoadTable, (const TableIdentifier&),
7982
(override));
8083

src/iceberg/transaction.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
#pragma once
2222

2323
#include <memory>
24+
#include <vector>
2425

2526
#include "iceberg/iceberg_export.h"
27+
#include "iceberg/result.h"
2628
#include "iceberg/type_fwd.h"
2729

2830
namespace iceberg {
@@ -44,10 +46,12 @@ class ICEBERG_EXPORT Transaction {
4446

4547
/// \brief Apply the pending changes from all actions and commit
4648
///
47-
/// May throw ValidationException if any update cannot be applied to the current table
48-
/// metadata. May throw CommitFailedException if the updates cannot be committed due to
49-
/// conflicts.
50-
virtual void CommitTransaction() = 0;
49+
/// This method applies all pending data operations and metadata updates in the
50+
/// transaction and commits them to the table in a single atomic operation.
51+
///
52+
/// \return Status::OK if the transaction was committed successfully, or an error
53+
/// status if validation failed or the commit encountered conflicts
54+
virtual Status CommitTransaction() = 0;
5155
};
5256

5357
} // namespace iceberg

0 commit comments

Comments
 (0)