gty404 commented on code in PR #257:
URL: https://github.com/apache/iceberg-cpp/pull/257#discussion_r2430922304
##########
src/iceberg/table_metadata.h:
##########
@@ -144,6 +145,203 @@ ICEBERG_EXPORT std::string ToString(const
SnapshotLogEntry& entry);
/// \brief Returns a string representation of a MetadataLogEntry
ICEBERG_EXPORT std::string ToString(const MetadataLogEntry& entry);
+/// \brief Builder class for constructing TableMetadata objects
+///
+/// This builder provides a fluent interface for creating and modifying table
metadata.
+/// It supports both creating new tables and building from existing metadata.
+///
+/// Each modification method generates a corresponding MetadataUpdate that is
tracked
+/// in a changes list. This allows the builder to maintain a complete history
of all
+/// modifications made to the table metadata, which is important for tracking
table
+/// evolution and for serialization purposes.
+class ICEBERG_EXPORT TableMetadataBuilder {
+ public:
+ /// \brief Create a builder for a new table
+ ///
+ /// \param format_version The format version for the table
+ /// \return A new TableMetadataBuilder instance
+ static TableMetadataBuilder BuildFromEmpty(
+ int8_t format_version = TableMetadata::kDefaultTableFormatVersion);
+
+ /// \brief Create a builder from existing table metadata
+ ///
+ /// \param base The base table metadata to build from
+ /// \return A new TableMetadataBuilder instance initialized with base
metadata
+ static TableMetadataBuilder BuildFrom(const std::shared_ptr<const
TableMetadata>& base);
+
+ /// \brief Assign a UUID to the table
+ ///
+ /// If no UUID is provided, a random UUID will be generated.
+ /// \return Reference to this builder for method chaining
+ TableMetadataBuilder& AssignUUID();
Review Comment:
I have checked the corresponding interface for Java, and all the fields
supported in the current C++ have corresponding functions.
##########
src/iceberg/table_metadata.cc:
##########
@@ -196,4 +197,229 @@ Status TableMetadataUtil::Write(FileIO& io, const
std::string& location,
return io.WriteFile(location, json_string);
}
+// TableMetadataBuilder implementation
+
+struct TableMetadataBuilder::Impl {
+ // Base metadata (if building from existing metadata)
+ std::shared_ptr<const TableMetadata> base;
+
+ // Mutable fields that will be used to build the final TableMetadata
+ int8_t format_version;
Review Comment:
I consider making TableMetadata read-only, once TableMetadata is
constructed, it cannot be modified anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]