zeroshade commented on code in PR #401:
URL: https://github.com/apache/iceberg-go/pull/401#discussion_r2096071405
##########
table/updates.go:
##########
@@ -382,7 +389,74 @@ func NewRemoveSnapshotsUpdate(ids []int64) Update {
}
func (u *removeSnapshotsUpdate) Apply(builder *MetadataBuilder) error {
- return fmt.Errorf("%w: %s", iceberg.ErrNotImplemented,
UpdateRemoveSnapshots)
+ _, err := builder.RemoveSnapshots(u.SnapshotIDs)
+
+ return err
+}
+
+func (u *removeSnapshotsUpdate) PostCommit(preTable *Table, postTable *Table)
error {
+ filesToDelete := make(map[string]struct{})
+
+ for _, snap := range preTable.Metadata().Snapshots() {
+ if slices.Contains(u.SnapshotIDs, snap.SnapshotID) {
+ filesToDelete[snap.ManifestList] = struct{}{}
+ }
+ }
+
+ for _, snapId := range u.SnapshotIDs {
+ snap := preTable.SnapshotByID(snapId)
+ if snap == nil {
+ return errors.New("missing snapshot")
+ }
+
+ mans, err := snap.Manifests(preTable.fs)
+ if err != nil {
+ return err
+ }
+
+ for _, man := range mans {
+ filesToDelete[man.FilePath()] = struct{}{}
+
+ entries, err := man.FetchEntries(preTable.fs, false)
+ if err != nil {
+ return err
+ }
+
+ for _, entry := range entries {
+ filesToDelete[entry.DataFile().FilePath()] =
struct{}{}
+ }
+ }
Review Comment:
`Snapshot` objects have a `dataFiles` method which will return an iterator
over the files, maybe we can leverage this to encapsulate this logic more
rather than duplicate 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]