aokolnychyi commented on code in PR #11195:
URL: https://github.com/apache/iceberg/pull/11195#discussion_r1776041008


##########
api/src/main/java/org/apache/iceberg/util/ContentFileSet.java:
##########
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.util;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.iceberg.ContentFile;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterators;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+
+/**
+ * A custom set for {@link ContentFile} that maintains insertion order
+ *
+ * @param <F> the concrete Java class of a ContentFile instance
+ */
+public class ContentFileSet<F extends ContentFile<F>> implements Set<F>, 
Serializable {

Review Comment:
   We may need this logic for other types of files like `ManifestFile` or 
`DeleteFileHolder`. The wrapping logic is not that unique. What do you think 
about doing something like this?
   
   ```
   abstract class WrapperSet<T> implements Set<T> {
   
     private final Set<Wrapper<T>> wrappers;
   
     protected WrapperSet(Iterable<Wrapper<T>> wrappers) {
       this.wrappers = Sets.newLinkedHashSet(wrappers);
     }
   
     abstract Wrapper<T> wrapper();
   
     abstract Wrapper<T> wrap(T file);
   
      // common implementation without supporting NULL elements and objects of 
types other than T
   }
    ```
   
   Then we can have trivial `DeleteFileSet` and `DataFileSet` classes.
   
   ```
   public class DeleteFileSet extends WrapperSet<DeleteFile> {
   
     private static final ThreadLocal<Wrapper<DeleteFile>> WRAPPERS =
         ThreadLocal.withInitial(() -> DeleteFileWrapper.wrap(null));
   
     private DeleteFileSet(Iterable<Wrapper<DeleteFile>> wrappers) {
         super(wrappers);
     }
   
     public static DeleteFileSet create() {
       return new DeleteFileSet(...);
     }
   
     public static DeleteFileSet of(Iterable<? extends DeleteFile> files) {
       return new DeleteFileSet(...);
     }
   
     @Override
     Wrapper<DeleteFile> wrapper() {
         return WRAPPERS.get();
     }
   
     @Override
     Wrapper<DeleteFile> wrap(DeleteFile file) {
         return new DeleteFileWrapper(file);
     }
   
     private static class DeleteFileWrapper implements Wrapper<DeleteFile> {
       private DeleteFile file;
   
       private DeleteFileWrapper(DeleteFile file) {
         this.file = file;
       }
   
       // equals and hashCode
     }
   }
   ```
   



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