leaves12138 commented on code in PR #6794:
URL: https://github.com/apache/paimon/pull/6794#discussion_r2610126429


##########
paimon-core/src/main/java/org/apache/paimon/globalindex/GlobalIndexScanBuilder.java:
##########
@@ -18,21 +18,77 @@
 
 package org.apache.paimon.globalindex;
 
-import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.partition.PartitionPredicate;
+import org.apache.paimon.predicate.Predicate;
+import org.apache.paimon.utils.IOUtils;
 import org.apache.paimon.utils.Range;
 
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static 
org.apache.paimon.utils.ManifestReadThreadPool.randomlyExecuteSequentialReturn;
 
 /** Builder for scanning global indexes. */
 public interface GlobalIndexScanBuilder {
 
     GlobalIndexScanBuilder withSnapshot(long snapshotId);
 
-    GlobalIndexScanBuilder withPartition(BinaryRow binaryRow);
+    GlobalIndexScanBuilder withSnapshot(Snapshot snapshot);
+
+    GlobalIndexScanBuilder withPartitionPredicate(PartitionPredicate 
partitionPredicate);
 
     GlobalIndexScanBuilder withRowRange(Range rowRange);
 
     RowRangeGlobalIndexScanner build();
 
-    Set<Range> shardList();
+    // Return sorted and no overlap ranges
+    List<Range> shardList();
+
+    static Optional<GlobalIndexResult> parallelScan(
+            final List<Range> ranges,
+            final GlobalIndexScanBuilder globalIndexScanBuilder,
+            final Predicate filter) {
+        List<RowRangeGlobalIndexScanner> scanners =
+                ranges.stream()
+                        .map(globalIndexScanBuilder::withRowRange)
+                        .map(GlobalIndexScanBuilder::build)
+                        .collect(Collectors.toList());
+
+        try {
+            List<Optional<GlobalIndexResult>> rowsResults = new ArrayList<>();
+            Iterator<Optional<GlobalIndexResult>> resultIterators =
+                    randomlyExecuteSequentialReturn(
+                            scanner -> {
+                                Optional<GlobalIndexResult> result = 
scanner.scan(filter);
+                                return Collections.singletonList(result);
+                            },
+                            scanners,
+                            null);

Review Comment:
   OK



##########
paimon-core/src/main/java/org/apache/paimon/globalindex/GlobalIndexScanBuilderImpl.java:
##########
@@ -19,109 +19,171 @@
 package org.apache.paimon.globalindex;
 
 import org.apache.paimon.Snapshot;
-import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.fs.FileIO;
 import org.apache.paimon.index.GlobalIndexMeta;
 import org.apache.paimon.index.IndexFileHandler;
+import org.apache.paimon.index.IndexPathFactory;
 import org.apache.paimon.manifest.IndexManifestEntry;
-import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.partition.PartitionPredicate;
+import org.apache.paimon.types.RowType;
 import org.apache.paimon.utils.Filter;
+import org.apache.paimon.utils.Pair;
 import org.apache.paimon.utils.Range;
 import org.apache.paimon.utils.SnapshotManager;
 
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
-import java.util.Set;
 import java.util.stream.Collectors;
 
 /** Implementation of {@link GlobalIndexScanBuilder}. */
 public class GlobalIndexScanBuilderImpl implements GlobalIndexScanBuilder {
 
-    private final FileStoreTable fileStoreTable;
+    private final Options options;
+    private final RowType rowType;
+    private final FileIO fileIO;
+    private final IndexPathFactory indexPathFactory;
     private final SnapshotManager snapshotManager;
-
-    private Long snapshotId;
-    private BinaryRow partition;
-    private Long rowRangeStart;
-    private Long rowRangeEnd;
-
-    public GlobalIndexScanBuilderImpl(FileStoreTable fileStoreTable) {
-        this.fileStoreTable = fileStoreTable;
-        this.snapshotManager = fileStoreTable.snapshotManager();
+    private final IndexFileHandler indexFileHandler;
+
+    private Snapshot snapshot;
+    private PartitionPredicate partitionPredicate;
+    private Range rowRange;
+
+    public GlobalIndexScanBuilderImpl(
+            Options options,
+            RowType rowType,
+            FileIO fileIO,
+            IndexPathFactory indexPathFactory,
+            SnapshotManager snapshotManager,
+            IndexFileHandler indexFileHandler) {
+        this.options = options;
+        this.rowType = rowType;
+        this.fileIO = fileIO;
+        this.indexPathFactory = indexPathFactory;
+        this.snapshotManager = snapshotManager;
+        this.indexFileHandler = indexFileHandler;
     }
 
     @Override
     public GlobalIndexScanBuilder withSnapshot(long snapshotId) {
-        this.snapshotId = snapshotId;
+        this.snapshot = snapshotManager.snapshot(snapshotId);
+        return this;
+    }
+
+    @Override
+    public GlobalIndexScanBuilder withSnapshot(Snapshot snapshot) {
+        this.snapshot = snapshot;
         return this;
     }
 
     @Override
-    public GlobalIndexScanBuilder withPartition(BinaryRow binaryRow) {
-        this.partition = binaryRow;
+    public GlobalIndexScanBuilder withPartitionPredicate(PartitionPredicate 
partitionPredicate) {
+        this.partitionPredicate = partitionPredicate;
         return this;
     }
 
     @Override
     public GlobalIndexScanBuilder withRowRange(Range rowRange) {
-        this.rowRangeStart = rowRange.from;
-        this.rowRangeEnd = rowRange.to;
+        this.rowRange = rowRange;
         return this;
     }
 
     @Override
     public RowRangeGlobalIndexScanner build() {
-        Objects.requireNonNull(rowRangeStart, "rowRangeStart must not be 
null");
-        Objects.requireNonNull(rowRangeEnd, "rowRangeEnd must not be null");
+        Objects.requireNonNull(rowRange, "rowRange must not be null");
         List<IndexManifestEntry> entries = scan();
-        return new RowRangeGlobalIndexScanner(fileStoreTable, rowRangeStart, 
rowRangeEnd, entries);
+        return new RowRangeGlobalIndexScanner(
+                options, rowType, fileIO, indexPathFactory, rowRange, entries);
     }
 
     @Override
-    public Set<Range> shardList() {
-        return scan().stream()
-                .map(
-                        entry -> {
-                            GlobalIndexMeta globalIndexMeta = 
entry.indexFile().globalIndexMeta();
-                            if (globalIndexMeta == null) {
-                                return null;
-                            }
-                            long start = globalIndexMeta.rowRangeStart();
-                            long end = globalIndexMeta.rowRangeEnd();
-                            return new Range(start, end);
-                        })
-                .filter(Objects::nonNull)
-                .collect(Collectors.toSet());
+    public List<Range> shardList() {
+        Map<String, List<Range>> indexRanges =
+                scan().stream()

Review Comment:
   OK



##########
paimon-core/src/main/java/org/apache/paimon/globalindex/ReaderWithScore.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.globalindex;
+
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.reader.RecordReader;
+import org.apache.paimon.reader.ScoreRecordIterator;
+import org.apache.paimon.utils.ProjectedRow;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Map;
+
+/** Return value with score. */
+public class ReaderWithScore implements RecordReader<InternalRow> {

Review Comment:
   OK



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