wuchong commented on a change in pull request #12303:
URL: https://github.com/apache/flink/pull/12303#discussion_r435667861



##########
File path: 
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/rank/AppendOnlyTopNFunction.java
##########
@@ -210,14 +210,19 @@ private void processElementWithoutRowNumber(RowData 
input, Collector<RowData> ou
                        RowData lastKey = lastEntry.getKey();
                        List<RowData> lastList = (List<RowData>) 
lastEntry.getValue();
                        // remove last one
-                       RowData lastElement = lastList.remove(lastList.size() - 
1);
-                       if (lastList.isEmpty()) {
+                       int size = lastList.size();
+                       RowData lastElement = null;
+                       if (size > 0) {
+                               lastElement = lastList.get(size - 1);

Review comment:
       Yes. I think we should improve `TopNBuffer#removeLast`, we can call 
`remove(index)` and `get(index)` when it is a `List`.




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

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


Reply via email to