zeroshade commented on code in PR #401:
URL: https://github.com/apache/iceberg-go/pull/401#discussion_r2175426593


##########
table/updates.go:
##########
@@ -382,7 +390,85 @@ 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(ctx context.Context, preTable 
*Table, postTable *Table) error {
+       prefs, err := preTable.FS(ctx)
+       if err != nil {
+               return err
+       }
+
+       filesToDelete := make(map[string]struct{})
+
+       for _, snapId := range u.SnapshotIDs {
+               snap := preTable.Metadata().SnapshotByID(snapId)
+               if snap == nil {
+                       return errors.New("snapshot should never be nil")
+               }
+
+               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(prefs)
+               if err != nil {
+                       return err
+               }
+
+               for _, man := range mans {
+                       filesToDelete[man.FilePath()] = struct{}{}
+
+                       entries, err := man.FetchEntries(prefs, false)
+                       if err != nil {
+                               return err
+                       }
+
+                       for _, entry := range entries {
+                               filesToDelete[entry.DataFile().FilePath()] = 
struct{}{}
+                       }
+               }
+       }
+
+       for _, snap := range postTable.Metadata().Snapshots() {
+               mans, err := snap.Manifests(prefs)
+               if err != nil {
+                       return err
+               }
+
+               for _, man := range mans {
+                       delete(filesToDelete, man.FilePath())
+
+                       entries, err := man.FetchEntries(prefs, false)
+                       if err != nil {
+                               return err
+                       }
+
+                       for _, entry := range entries {
+                               if entry.Status() != iceberg.EntryStatusDELETED 
{
+                                       delete(filesToDelete, 
entry.DataFile().FilePath())
+                               }
+                       }
+               }
+       }
+
+       var res error
+
+       for f := range filesToDelete {
+               if err := prefs.Remove(f); err != nil {
+                       res = errors.Join(res, err)
+               }
+               fmt.Println("remove", f)

Review Comment:
   this should be a log line or something, but either way should not be 
printing to the console.



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