You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/27 02:45:01 UTC

[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #104: [FLINK-27336] Avoid merging when there is only one record

JingsongLi commented on code in PR #104:
URL: https://github.com/apache/flink-table-store/pull/104#discussion_r859320053


##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/SortBufferMemTable.java:
##########
@@ -166,19 +169,31 @@ private void advanceIfNeeded() {
                 if (previousRow == null) {
                     return;
                 }
-                mergeFunction.reset();
-                mergeFunction.add(previous.getReusedKv().value());
 
+                boolean hasOne = true;
                 while (readOnce()) {
                     if (keyComparator.compare(
                                     previous.getReusedKv().key(), current.getReusedKv().key())
                             != 0) {
                         break;
                     }
+                    // avoid merging when there is only one record
+                    if (hasOne) {
+                        mergeFunction.reset();
+                        mergeFunction.add(previous.getReusedKv().value());
+                        hasOne = false;
+                    }
                     mergeFunction.add(current.getReusedKv().value());
                     swapSerializers();
                 }
-                result = mergeFunction.getValue();
+                RowData previousValue = previous.getReusedKv().value();
+                result =
+                        hasOne
+                                ? mergeFunction instanceof ValueCountMergeFunction

Review Comment:
   I think we can ignore that count is zero for `ValueCountMergeFunction`.
   Because if there is no merge, the count should never be zero.



##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/SortBufferMemTable.java:
##########
@@ -166,19 +169,31 @@ private void advanceIfNeeded() {
                 if (previousRow == null) {
                     return;
                 }
-                mergeFunction.reset();
-                mergeFunction.add(previous.getReusedKv().value());
 
+                boolean hasOne = true;

Review Comment:
   `hasOne = true` -> `mergeFuncInitialized = false`?



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

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