zeroshade commented on code in PR #1416:
URL: https://github.com/apache/iceberg-go/pull/1416#discussion_r3553759015
##########
table/metadata.go:
##########
@@ -283,6 +283,59 @@ func MetadataBuilderFromBase(metadata Metadata,
currentFileLocation string) (*Me
return b, nil
}
+func cloneMetadataBuilderInt[T any](value *T) *T {
+ if value == nil {
+ return nil
+ }
+
+ cloned := *value
+
+ return &cloned
+}
+
+// clone returns a metadata-builder copy suitable for staging updates.
+// The copy shares only immutable data with the original builder and keeps
+// value types separated so partial update attempts remain atomic.
+func (b *MetadataBuilder) clone() *MetadataBuilder {
+ if b == nil {
+ return nil
+ }
+
+ cloned := &MetadataBuilder{
+ base: b.base,
+ updates: append([]Update(nil), b.updates...),
+ formatVersion: b.formatVersion,
+ uuid: b.uuid,
+ loc: b.loc,
+ lastUpdatedMS: b.lastUpdatedMS,
+ lastColumnId: b.lastColumnId,
+ schemaList: slices.Clone(b.schemaList),
+ currentSchemaID: b.currentSchemaID,
+ specs: slices.Clone(b.specs),
+ defaultSpecID: b.defaultSpecID,
+ lastPartitionID: b.lastPartitionID,
Review Comment:
nit: `lastPartitionID` is shallow-copied here while the other
`*int`/`*int64` fields go through `cloneMetadataBuilderInt`. Safe today
(mutations reassign the pointer rather than write through it), but inconsistent
and a latent atomicity hole if that ever changes. The full manual field
enumeration is also a bit fragile — `cloned := *b` then overriding only the
reference types would be more robust.
--
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]