liming30 commented on code in PR #833:
URL: https://github.com/apache/incubator-paimon/pull/833#discussion_r1169925050


##########
paimon-core/src/main/java/org/apache/paimon/mergetree/compact/LoserTree.java:
##########
@@ -0,0 +1,345 @@
+/*
+ * 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.mergetree.compact;
+
+import org.apache.paimon.reader.RecordReader;
+import org.apache.paimon.utils.ExceptionUtils;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * A variant of the loser tree. In the LSM-Tree architecture, there will be 
duplicate Keys in
+ * multiple {@link RecordReader}, and these Keys need to be merged. In the 
loser tree, we return in
+ * the order of the Keys, but because the returned objects may be reused in 
the {@link RecordReader}
+ * or the {@link MergeFunction}, for a single {@link RecordReader}, we cannot 
get the next Key
+ * immediately after returning a Key, and we need to wait until the same Key 
in all {@link
+ * RecordReader} is returned before proceeding to the next Key.
+ *
+ * <p>The process of building the loser tree is the same as a regular loser 
tree. The difference is
+ * that in the process of adjusting the tree, we need to record the index of 
the same key and the
+ * state of the winner/loser for subsequent quick adjustment of the position 
of the winner.
+ *
+ * <p>Detailed design can refer to
+ * 
https://docs.google.com/document/d/1OPyb9o9K226Fb4O-SzZpBYgwfsvNY7X0H5T3ivdu1ck/edit?usp=sharing
+ */
+public class LoserTree<T> implements Closeable {
+    private final int[] tree;
+    private final int size;
+    private final List<LeafIterator<T>> leaves;
+    private final Comparator<T> firstComparator;
+    private final Comparator<T> secondComparator;

Review Comment:
   If comparator.compare('a', 'b') > 0, then 'a' is the winner. In the 
following implementation, we always let 'a' represent the parent node.
   



##########
paimon-core/src/main/java/org/apache/paimon/mergetree/compact/LoserTree.java:
##########
@@ -0,0 +1,345 @@
+/*
+ * 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.mergetree.compact;
+
+import org.apache.paimon.reader.RecordReader;
+import org.apache.paimon.utils.ExceptionUtils;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * A variant of the loser tree. In the LSM-Tree architecture, there will be 
duplicate Keys in
+ * multiple {@link RecordReader}, and these Keys need to be merged. In the 
loser tree, we return in
+ * the order of the Keys, but because the returned objects may be reused in 
the {@link RecordReader}
+ * or the {@link MergeFunction}, for a single {@link RecordReader}, we cannot 
get the next Key
+ * immediately after returning a Key, and we need to wait until the same Key 
in all {@link
+ * RecordReader} is returned before proceeding to the next Key.
+ *
+ * <p>The process of building the loser tree is the same as a regular loser 
tree. The difference is
+ * that in the process of adjusting the tree, we need to record the index of 
the same key and the
+ * state of the winner/loser for subsequent quick adjustment of the position 
of the winner.
+ *
+ * <p>Detailed design can refer to
+ * 
https://docs.google.com/document/d/1OPyb9o9K226Fb4O-SzZpBYgwfsvNY7X0H5T3ivdu1ck/edit?usp=sharing
+ */
+public class LoserTree<T> implements Closeable {
+    private final int[] tree;
+    private final int size;
+    private final List<LeafIterator<T>> leaves;
+    private final Comparator<T> firstComparator;
+    private final Comparator<T> secondComparator;

Review Comment:
   resolved.



-- 
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...@paimon.apache.org

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

Reply via email to