JingsongLi commented on code in PR #6609:
URL: https://github.com/apache/paimon/pull/6609#discussion_r2533261545


##########
paimon-core/src/main/java/org/apache/paimon/index/globalindex/GlobalIndexResult.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.paimon.index.globalindex;
+
+import org.apache.paimon.utils.Range;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/** Result of a global index query. */
+public interface GlobalIndexResult {
+
+    GlobalIndexResult ALL =
+            new GlobalIndexResult() {
+                @Override
+                public GlobalIndexResult and(GlobalIndexResult 
fileIndexResult) {
+                    return fileIndexResult;
+                }
+
+                @Override
+                public GlobalIndexResult or(GlobalIndexResult fileIndexResult) 
{
+                    return this;
+                }
+
+                @Override
+                public boolean empty() {
+                    return false;
+                }
+
+                @Override
+                public Iterator<Range> results() {
+                    throw new UnsupportedOperationException(
+                            "ALL result does not support results()");
+                }
+            };
+
+    GlobalIndexResult NONE =
+            new GlobalIndexResult() {
+                @Override
+                public GlobalIndexResult and(GlobalIndexResult 
fileIndexResult) {
+                    return this;
+                }
+
+                @Override
+                public GlobalIndexResult or(GlobalIndexResult fileIndexResult) 
{
+                    return fileIndexResult;
+                }
+
+                @Override
+                public boolean empty() {
+                    return true;
+                }
+
+                @Override
+                public Iterator<Range> results() {
+                    return Collections.emptyIterator();
+                }
+            };
+
+    default GlobalIndexResult and(GlobalIndexResult fileIndexResult) {
+        if (empty() || fileIndexResult.empty()) {
+            return NONE;
+        }
+
+        Iterator<Range> it1 = results();
+        Iterator<Range> it2 = fileIndexResult.results();
+
+        Set<Range> intersection = RangeUtils.and(it1, it2);
+
+        return wrap(intersection);
+    }
+
+    default GlobalIndexResult or(GlobalIndexResult fileIndexResult) {
+        if (empty()) {
+            return fileIndexResult;
+        }
+        if (fileIndexResult.empty()) {
+            return this;
+        }
+
+        Iterator<Range> it1 = results();
+        Iterator<Range> it2 = fileIndexResult.results();
+
+        Set<Range> intersection = RangeUtils.or(it1, it2);
+
+        return wrap(intersection);
+    }
+
+    boolean empty();
+
+    Iterator<Range> results();

Review Comment:
   You can just introduce results to an unified `IndexResult`.



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

Reply via email to