WZhuo commented on code in PR #386:
URL: https://github.com/apache/iceberg-cpp/pull/386#discussion_r2597423970


##########
src/iceberg/table_metadata.cc:
##########
@@ -258,13 +290,95 @@ Result<std::unique_ptr<TableMetadata>> 
TableMetadataUtil::Read(
   return TableMetadataFromJson(json);
 }
 
+Status TableMetadataUtil::Write(FileIO& io, const TableMetadata* base,
+                                TableMetadata* metadata) {
+  ICEBERG_CHECK(metadata != nullptr, "The metadata is nullptr.");
+
+  int version = -1;
+  if (base != nullptr && !base->metadata_file_location.empty()) {
+    // parse current version from location
+    version = ParseVersionFromLocation(base->metadata_file_location);
+  }
+
+  ICEBERG_ASSIGN_OR_RAISE(std::string new_file_location,
+                          NewTableMetadataFilePath(*metadata, version + 1));
+  ICEBERG_RETURN_UNEXPECTED(Write(io, new_file_location, *metadata));
+  metadata->metadata_file_location = std::move(new_file_location);
+  return {};
+}
+
 Status TableMetadataUtil::Write(FileIO& io, const std::string& location,
                                 const TableMetadata& metadata) {
   auto json = ToJson(metadata);
   ICEBERG_ASSIGN_OR_RAISE(auto json_string, ToJsonString(json));
   return io.WriteFile(location, json_string);
 }
 
+void TableMetadataUtil::DeleteRemovedMetadataFiles(FileIO& io, const 
TableMetadata* base,
+                                                   const TableMetadata* 
metadata) {
+  if (!base) {
+    return;
+  }
+
+  bool delete_after_commit = 
TableProperties::kMetadataDeleteAfterCommitEnabled.value();
+  if (auto it = metadata->properties.find(
+          TableProperties::kMetadataDeleteAfterCommitEnabled.key());
+      it != metadata->properties.end()) {
+    delete_after_commit = StringUtils::ToLower(it->second) == "true" || 
it->second == "1";

Review Comment:
   Fix it



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