zeroshade commented on code in PR #339:
URL: https://github.com/apache/iceberg-go/pull/339#discussion_r2003624295
##########
catalog/internal/utils.go:
##########
@@ -61,3 +64,57 @@ func WriteMetadata(ctx context.Context, metadata
table.Metadata, loc string, pro
return json.NewEncoder(out).Encode(metadata)
}
+
+func UpdateTableMetadata(base table.Metadata, updates []table.Update,
metadataLoc string) (table.Metadata, error) {
+ bldr, err := table.MetadataBuilderFromBase(base)
+ if err != nil {
+ return nil, err
+ }
+
+ for _, update := range updates {
+ if err := update.Apply(bldr); err != nil {
+ return nil, err
+ }
+ }
+
+ if bldr.HasChanges() {
+ if metadataLoc != "" {
+ maxMetadataLogEntries := max(1,
+ base.Properties().GetInt(
+ table.MetadataPreviousVersionsMaxKey,
table.MetadataPreviousVersionsMaxDefault))
+
+ bldr.TrimMetadataLogs(maxMetadataLogEntries + 1).
+ AppendMetadataLog(table.MetadataLogEntry{
+ MetadataFile: metadataLoc,
+ TimestampMs: base.LastUpdatedMillis(),
+ })
+ }
+ if base.LastUpdatedMillis() == bldr.LastUpdatedMS() {
+ bldr.SetLastUpdatedMS()
+ }
+ }
+
+ return bldr.Build()
+}
+
+var tableMetadataFileNameRegex =
regexp.MustCompile(`^(\d+)-([\w-]{36})(?:\.\w+)?\.metadata\.json`)
Review Comment:
added explanation via comments
--
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]