gty404 commented on code in PR #257:
URL: https://github.com/apache/iceberg-cpp/pull/257#discussion_r2432826097


##########
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:
   There is a SetLocation similar to it, and I mistakenly thought it was the 
same method. I am adding a new interface.



##########
src/iceberg/table_metadata.h:
##########
@@ -144,6 +144,202 @@ 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 std::unique_ptr<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 std::unique_ptr<TableMetadataBuilder> BuildFrom(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();
+
+  /// \brief Assign a specific UUID to the table
+  ///
+  /// \param uuid The UUID string to assign
+  /// \return Reference to this builder for method chaining
+  TableMetadataBuilder& AssignUUID(std::string_view uuid);
+
+  /// \brief Upgrade the format version of the table
+  ///
+  /// \param new_format_version The new format version (must be >= current 
version)
+  /// \return Reference to this builder for method chaining
+  TableMetadataBuilder& UpgradeFormatVersion(int8_t new_format_version);
+
+  /// \brief Set the current schema for the table
+  ///
+  /// \param schema The schema to set as current
+  /// \param new_last_column_id The highest column ID in the schema
+  /// \return Reference to this builder for method chaining
+  TableMetadataBuilder& SetCurrentSchema(std::shared_ptr<Schema> schema,
+                                         int32_t new_last_column_id);
+
+  /// \brief Set the current schema by schema ID
+  ///
+  /// \param schema_id The ID of the schema to set as current
+  /// \return Reference to this builder for method chaining
+  TableMetadataBuilder& SetCurrentSchema(int32_t schema_id);
+
+  /// \brief Add a schema to the table
+  ///
+  /// \param schema The schema to add
+  /// \return Reference to this builder for method chaining
+  TableMetadataBuilder& AddSchema(std::shared_ptr<Schema> schema);
+
+  /// \brief Set the default partition spec for the table
+  ///
+  /// \param spec The partition spec to set as default
+  /// \return Reference to this builder for method chaining
+  TableMetadataBuilder& SetDefaultPartitionSpec(std::shared_ptr<PartitionSpec> 
spec);

Review Comment:
   I prefer the third option



-- 
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]

Reply via email to