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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to