JingsongLi commented on code in PR #1072:
URL: https://github.com/apache/incubator-paimon/pull/1072#discussion_r1185749942


##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreScan.java:
##########
@@ -316,19 +321,28 @@ private boolean filterManifestFileMeta(ManifestFileMeta 
manifest) {
     }
 
     /** Note: Keep this thread-safe. */
-    private boolean filterByBucket(ManifestEntry entry) {
+    private boolean filterByBucket(AbstractManifestEntry entry) {
         return (specifiedBucket == null || entry.bucket() == specifiedBucket);
     }
 
     /** Note: Keep this thread-safe. */
-    private boolean filterByBucketSelector(ManifestEntry entry) {
+    private boolean filterByBucketSelector(AbstractManifestEntry entry) {
         return (bucketSelector == null
                 || bucketSelector.select(entry.bucket(), 
entry.totalBuckets()));
     }
 
     /** Note: Keep this thread-safe. */
-    private boolean filterByLevel(ManifestEntry entry) {
-        return (levelFilter == null || levelFilter.test(entry.file().level()));
+    private boolean filterByLevel(AbstractManifestEntry entry) {
+        return (levelFilter == null || levelFilter.test(entry.level()));
+    }
+
+    /** Note: Keep this thread-safe. */
+    private boolean filterByStats(AbstractManifestEntry entry) {
+        if (entry instanceof ManifestEntry) {
+            return filterByStats((ManifestEntry) entry);
+        } else {
+            throw new RuntimeException("only complete manifest entry could be 
filter by stats");

Review Comment:
   return true;



##########
paimon-core/src/main/java/org/apache/paimon/utils/ParallellyExecuteUtils.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.utils;
+
+import java.util.ArrayDeque;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
+
+/**
+ * This class is a parallel execution util class, which mainly aim to process 
tasks parallelly with
+ * memory control.
+ */
+public class ParallellyExecuteUtils {
+
+    // reduce memory usage by batch iterable process, the cached result in 
memory will be 2 *
+    // queueSize
+    public static <T, U> Iterable<T> parallelismBatchIterable(
+            Function<List<U>, List<T>> processor, List<U> input, int 
queueSize) {

Review Comment:
   default value of queueSize can be COMMON_IO_FORK_JOIN_POOL thread number * 2.



##########
paimon-core/src/main/java/org/apache/paimon/utils/ParallellyExecuteUtils.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.utils;
+
+import java.util.ArrayDeque;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
+
+/**
+ * This class is a parallel execution util class, which mainly aim to process 
tasks parallelly with
+ * memory control.
+ */
+public class ParallellyExecuteUtils {
+
+    // reduce memory usage by batch iterable process, the cached result in 
memory will be 2 *
+    // queueSize
+    public static <T, U> Iterable<T> parallelismBatchIterable(
+            Function<List<U>, List<T>> processor, List<U> input, int 
queueSize) {
+        if (queueSize <= 0) {
+            throw new NegativeArraySizeException("queueSize need to be 
positive");
+        }
+
+        Queue<List<U>> stack = new ArrayDeque<>();
+        int size = input.size();
+        int num = size / queueSize;
+
+        for (int i = 0; i < num; i++) {
+            stack.add(input.subList(i * queueSize, (i + 1) * queueSize));
+        }
+
+        if (num * queueSize < size) {
+            stack.add(input.subList(num * queueSize, size));
+        }
+
+        return () ->
+                new Iterator<T>() {
+                    CompletableFuture<List<T>> batch = null;
+                    List<T> activeList = null;
+                    private int index = 0;
+                    private T next = null;
+
+                    // build the first batch
+                    {
+                        if (stack.size() > 0) {
+                            batch =
+                                    CompletableFuture.supplyAsync(
+                                            () -> 
processor.apply(stack.poll()),
+                                            
FileUtils.COMMON_IO_FORK_JOIN_POOL);
+                        }
+                    }
+
+                    @Override
+                    public boolean hasNext() {
+                        try {
+                            // get active list for polling, and submit tasks 
meanwhile
+                            if (activeList == null) {
+                                if (batch == null) {
+                                    return false;
+                                }
+
+                                activeList = batch.get();
+                                if (stack.size() > 0) {
+                                    batch =
+                                            CompletableFuture.supplyAsync(
+                                                    () -> 
processor.apply(stack.poll()),
+                                                    
FileUtils.COMMON_IO_FORK_JOIN_POOL);
+                                } else {
+                                    batch = null;
+                                }
+                            }
+                            if (index < activeList.size()) {
+                                next = activeList.get(index++);
+                                if (index == activeList.size()) {
+                                    activeList = null;

Review Comment:
   You implement a wrong iterator.
   Test should cover multiple invoking for `hasNext `.



##########
paimon-core/src/main/java/org/apache/paimon/utils/ParallellyExecuteUtils.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.utils;
+
+import java.util.ArrayDeque;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
+
+/**
+ * This class is a parallel execution util class, which mainly aim to process 
tasks parallelly with
+ * memory control.
+ */
+public class ParallellyExecuteUtils {
+
+    // reduce memory usage by batch iterable process, the cached result in 
memory will be 2 *
+    // queueSize
+    public static <T, U> Iterable<T> parallelismBatchIterable(
+            Function<List<U>, List<T>> processor, List<U> input, int 
queueSize) {
+        if (queueSize <= 0) {
+            throw new NegativeArraySizeException("queueSize need to be 
positive");
+        }
+
+        Queue<List<U>> stack = new ArrayDeque<>();
+        int size = input.size();
+        int num = size / queueSize;
+
+        for (int i = 0; i < num; i++) {
+            stack.add(input.subList(i * queueSize, (i + 1) * queueSize));
+        }
+
+        if (num * queueSize < size) {
+            stack.add(input.subList(num * queueSize, size));
+        }
+
+        return () ->
+                new Iterator<T>() {
+                    CompletableFuture<List<T>> batch = null;
+                    List<T> activeList = null;
+                    private int index = 0;
+                    private T next = null;
+
+                    // build the first batch
+                    {
+                        if (stack.size() > 0) {
+                            batch =
+                                    CompletableFuture.supplyAsync(
+                                            () -> 
processor.apply(stack.poll()),
+                                            
FileUtils.COMMON_IO_FORK_JOIN_POOL);
+                        }
+                    }
+
+                    @Override
+                    public boolean hasNext() {
+                        try {
+                            // get active list for polling, and submit tasks 
meanwhile
+                            if (activeList == null) {
+                                if (batch == null) {
+                                    return false;
+                                }
+
+                                activeList = batch.get();
+                                if (stack.size() > 0) {
+                                    batch =
+                                            CompletableFuture.supplyAsync(

Review Comment:
   We don't need to produce more elements when the consumer not finish this 
batch.



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