Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/iceberg/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/iceberg/catalog/memory/in_memory_catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't need to move lock, we can use std::lock_guard<> instead. Can you help to modify the other cases in this file? Or we can open a new PR to do this.

return NotImplemented("rename table");
}

Result<std::unique_ptr<Table>> InMemoryCatalog::LoadTable(
const TableIdentifier& identifier) {
if (!file_io_) [[unlikely]] {
Expand Down
2 changes: 2 additions & 0 deletions src/iceberg/catalog/memory/in_memory_catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/iceberg/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/iceberg/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/iceberg/test/mock_catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
12 changes: 8 additions & 4 deletions src/iceberg/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#pragma once

#include <memory>
#include <vector>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include this?


#include "iceberg/iceberg_export.h"
#include "iceberg/result.h"
#include "iceberg/type_fwd.h"

namespace iceberg {
Expand All @@ -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
Loading