Skip to content

Commit 66cffc5

Browse files
committed
feat: add PendingUpdateTyped template class
Add PendingUpdateTyped template class to provide type-safe Apply() method for table metadata changes. This allows different operations to return specific result types (e.g., vector<Snapshot> for ExpireSnapshots). Changes: - Add PendingUpdateTyped<T> template extending PendingUpdate - Move typed Apply() method from base to template class - Remove ErrorCollector base from PendingUpdate (simplified design) This is needed for ExpireSnapshots which returns vector<Snapshot> from Apply().
1 parent 720c566 commit 66cffc5

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/iceberg/pending_update.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "iceberg/iceberg_export.h"
2626
#include "iceberg/result.h"
2727
#include "iceberg/type_fwd.h"
28-
#include "iceberg/util/error_collector.h"
2928

3029
namespace iceberg {
3130

@@ -37,16 +36,10 @@ namespace iceberg {
3736
///
3837
/// This matches the Java Iceberg pattern where BaseTransaction stores a
3938
/// List<PendingUpdate> without type parameters.
40-
class ICEBERG_EXPORT PendingUpdate : public ErrorCollector {
39+
class ICEBERG_EXPORT PendingUpdate {
4140
public:
4241
virtual ~PendingUpdate() = default;
4342

44-
/// \brief Verify that the changes are valid and apply them.
45-
/// \return Status::OK if the changes are valid, or an error:
46-
/// - ValidationFailed: if pending changes cannot be applied
47-
/// - InvalidArgument: if pending changes are conflicting
48-
virtual Status Apply() = 0;
49-
5043
/// \brief Apply and commit the pending changes to the table
5144
///
5245
/// Changes are committed by calling the underlying table's commit operation.
@@ -69,4 +62,33 @@ class ICEBERG_EXPORT PendingUpdate : public ErrorCollector {
6962
PendingUpdate() = default;
7063
};
7164

65+
/// \brief Template class for type-safe table metadata changes using builder pattern
66+
///
67+
/// PendingUpdateTyped extends PendingUpdate with a type-safe Apply() method that
68+
/// returns the specific result type for each operation. Subclasses implement
69+
/// specific types of table updates such as schema changes, property updates, or
70+
/// snapshot-producing operations like appends and deletes.
71+
///
72+
/// Apply() can be used to validate and inspect the uncommitted changes before
73+
/// committing. Commit() applies the changes and commits them to the table.
74+
///
75+
/// \tparam T The type of result returned by Apply()
76+
template <typename T>
77+
class ICEBERG_EXPORT PendingUpdateTyped : public PendingUpdate {
78+
public:
79+
~PendingUpdateTyped() override = default;
80+
81+
/// \brief Apply the pending changes and return the uncommitted result
82+
///
83+
/// This does not result in a permanent update.
84+
///
85+
/// \return the uncommitted changes that would be committed, or an error:
86+
/// - ValidationFailed: if pending changes cannot be applied
87+
/// - InvalidArgument: if pending changes are conflicting
88+
virtual Result<T> Apply() = 0;
89+
90+
protected:
91+
PendingUpdateTyped() = default;
92+
};
93+
7294
} // namespace iceberg

0 commit comments

Comments
 (0)