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/28 02:18:41 UTC

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

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


##########
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:
   @JingsongLi, in theory the count should never be zero, but in current tests there is 0 test case. Hence I add this logic to avoid the zero situation.



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