laskoviymishka commented on code in PR #902:
URL: https://github.com/apache/iceberg-go/pull/902#discussion_r3089561743


##########
table/metadata.go:
##########
@@ -1164,6 +1171,56 @@ func (b *MetadataBuilder) RemoveSchemas(ints []int) 
error {
        return nil
 }
 
+// SetStatistics adds or replaces a statistics file for the given snapshot. If 
a statistics
+// file with the same snapshot ID already exists it is replaced, otherwise the 
file is appended.
+func (b *MetadataBuilder) SetStatistics(stats StatisticsFile) error {
+       replaced := false
+       for i, s := range b.statisticsList {
+               if s.SnapshotID == stats.SnapshotID {
+                       b.statisticsList[i] = stats
+                       replaced = true
+
+                       break
+               }
+       }
+
+       if !replaced {
+               b.statisticsList = append(b.statisticsList, stats)
+       }
+
+       b.updates = append(b.updates, NewSetStatisticsUpdate(stats))
+
+       return nil
+}
+
+// RemoveStatistics removes the statistics file associated with the given 
snapshot ID.
+// It is not an error if no such file exists.
+func (b *MetadataBuilder) RemoveStatistics(snapshotID int64) error {
+       b.statisticsList = slices.DeleteFunc(b.statisticsList, func(s 
StatisticsFile) bool {
+               return s.SnapshotID == snapshotID
+       })
+       b.updates = append(b.updates, NewRemoveStatisticsUpdate(snapshotID))
+
+       return nil
+}
+
+// AddEncryptionKey adds or replaces an encryption key indexed by its key-id.
+func (b *MetadataBuilder) AddEncryptionKey(key EncryptionKey) error {

Review Comment:
   Encryption keys are V3+. No format version check. The codebase already gates 
V3 features — see minFormatVersionRowLineage. Add a b.formatVersion < 3 guard.



##########
table/metadata.go:
##########
@@ -1312,7 +1370,8 @@ func (c *commonMetadata) Equals(other *commonMetadata) 
bool {
                c.LastColumnId == other.LastColumnId && c.CurrentSchemaID == 
other.CurrentSchemaID &&
                c.DefaultSpecID == other.DefaultSpecID && c.DefaultSortOrderID 
== other.DefaultSortOrderID &&
                slices.Equal(c.SnapshotLog, other.SnapshotLog) && 
slices.Equal(c.MetadataLog, other.MetadataLog) &&
-               iceinternal.SliceEqualHelper(c.SortOrderList, 
other.SortOrderList)
+               iceinternal.SliceEqualHelper(c.SortOrderList, 
other.SortOrderList) &&
+               maps.Equal(c.EncryptionKeyMap, other.EncryptionKeyMap)

Review Comment:
   i think this is a bug
   
   EncryptionKey has *string fields (KeyMetadata, KeyAlgorithm). maps.Equal 
uses == — compares pointer addresses, not values. Two keys deserialized from 
the same JSON will have different pointers. Equals() returns false for 
identical metadata. Use maps.EqualFunc with reflect.DeepEqual like SnapshotRefs 
three lines above.



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