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


##########
table/snapshot_producers.go:
##########
@@ -92,6 +92,65 @@ func (fa *fastAppendFiles) deletedEntries() 
([]iceberg.ManifestEntry, error) {
        return nil, nil
 }
 
+func newMergeFilesProducer(
+       op Operation,
+       txn *Transaction,
+       fs iceio.WriteFileIO,
+       commitUUID *uuid.UUID,
+       snapshotProps iceberg.Properties,
+       existingManifestFiles []iceberg.ManifestFile,
+       deletedManifestFiles []iceberg.ManifestFile,
+       deletedManifestEntries []iceberg.ManifestEntry,
+) *snapshotProducer {
+       prod := createSnapshotProducer(op, txn, fs, commitUUID, snapshotProps)
+       prod.producerImpl = &mergeFiles{
+               base:                   prod,
+               existingManifestFiles:  existingManifestFiles,
+               deletedManifestFiles:   deletedManifestFiles,
+               deletedManifestEntries: deletedManifestEntries,
+       }
+
+       return prod
+}
+
+type mergeFiles struct {
+       base *snapshotProducer
+
+       existingManifestFiles  []iceberg.ManifestFile
+       deletedManifestFiles   []iceberg.ManifestFile
+       deletedManifestEntries []iceberg.ManifestEntry
+}
+
+func (mf *mergeFiles) processManifests(manifests []iceberg.ManifestFile) 
([]iceberg.ManifestFile, error) {
+       var manifestsToKeep []iceberg.ManifestFile
+
+       for _, manifest := range manifests {
+               var found bool
+
+               for _, deletedManifest := range mf.deletedManifestFiles {
+                       if manifest.FilePath() == deletedManifest.FilePath() {
+                               found = true
+
+                               break
+                       }
+               }
+
+               if !found {
+                       manifestsToKeep = append(manifestsToKeep, manifest)
+               }
+       }

Review Comment:
   instead of spinning through multiple slices and having to pass in the 
original set of deleted manifests, why not do:
   
   ```go
   unmergedDataManifests, unmergedDeleteManifests := []iceberg.ManifestFile{}, 
[]iceberg.ManifestFile{}
   for _, m := range manifests {
           switch m.ManifestContent() {
           case iceberg.ManifestContentData:
                   unmergedDataManifests = append(unmergedDataManifests, m)
           case iceberg.ManifestContentDeletes:
                   unmergedDeleteManifests = append(unmergedDeleteManifests, m)
           }
   }
   ```
   



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to