wgtmac commented on code in PR #416:
URL: https://github.com/apache/iceberg-cpp/pull/416#discussion_r2650312665
##########
src/iceberg/table_metadata.cc:
##########
@@ -68,6 +130,100 @@ std::string ToString(const MetadataLogEntry& entry) {
entry.metadata_file);
}
+Result<std::unique_ptr<TableMetadata>> TableMetadata::Make(
+ const iceberg::Schema& schema, const iceberg::PartitionSpec& spec,
+ const iceberg::SortOrder& sort_order, const std::string& location,
+ const std::unordered_map<std::string, std::string>& properties, int
format_version) {
+ for (const auto& [key, _] : properties) {
+ if (TableProperties::reserved_properties().contains(key)) {
+ return InvalidArgument(
+ "Table properties should not contain reserved properties, but got
{}", key);
+ }
+ }
+
+ // Reassign all column ids to ensure consistency
+ int32_t last_column_id = 0;
+ auto next_id = [&last_column_id]() -> int32_t { return ++last_column_id; };
+ ICEBERG_ASSIGN_OR_RAISE(auto fresh_schema,
+ AssignFreshIds(Schema::kInitialSchemaId, schema,
next_id));
+
+ // Rebuild the partition spec using the new column ids
+ ICEBERG_ASSIGN_OR_RAISE(
+ auto fresh_spec,
+ FreshPartitionSpec(PartitionSpec::kInitialSpecId, spec, schema,
*fresh_schema));
+
+ // rebuild the sort order using the new column ids
+ ICEBERG_ASSIGN_OR_RAISE(
+ auto fresh_order,
+ FreshSortOrder(SortOrder::kInitialSortOrderId, sort_order, schema,
*fresh_schema))
+
+ // Validata the metrics configuration.
+ ICEBERG_RETURN_UNEXPECTED(
+ MetricsConfig::VerifyReferencedColumns(properties, *fresh_schema));
+
+
ICEBERG_RETURN_UNEXPECTED(PropertyUtil::ValidateCommitProperties(properties));
+
+ return TableMetadataBuilder::BuildFromEmpty(format_version)
+ ->SetLocation(location)
+ .SetCurrentSchema(std::move(fresh_schema), last_column_id)
+ .SetDefaultPartitionSpec(std::move(fresh_spec))
+ .SetDefaultSortOrder(std::move(fresh_order))
+ .SetProperties(properties)
+ .Build();
+}
+
+std::vector<std::unique_ptr<TableUpdate>> TableMetadata::ChangesForCreate()
const {
Review Comment:
I still prefer this function to be a static utility function instead of a
member function. The reason is to keep minimal functions in the `TableMetadata`
(only necessary convenience accessors) and this function is not supposed to be
used by downstream users.
--
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]