SEPURI-SAI-KRISHNA commented on code in PR #29410:
URL: https://github.com/apache/flink/pull/29410#discussion_r4682640098


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/over/AbstractNonTimeUnboundedPrecedingOver.java:
##########
@@ -422,6 +436,36 @@ RowData setAccumulatorAndGetValue(RowData accumulator) 
throws Exception {
         return aggFuncs.getValue();
     }
 
+    /**
+     * Reads the accumulator stored for a sort key, as a copy the caller owns.
+     *
+     * <p>An accumulator can hold mutable content, either a data view or a 
field such as a bitmap,
+     * an array or a {@code byte[]}. The aggregate functions change that 
content in place, and the
+     * heap state backend hands back the very object it stores. Without a 
copy, accumulating into
+     * one sort key's accumulator would also change the one state holds for 
another.
+     *
+     * @param accKey the sort key to read the accumulator of
+     * @return a private copy of the stored accumulator, or null if there is 
none
+     */
+    RowData getAccFromState(RowData accKey) throws Exception {
+        final RowData acc = accMapState.get(accKey);
+        return acc == null ? null : accSerializer.copy(acc);

Review Comment:
   Measured it: 100M rows, SUM/COUNT/MIN/MAX/AVG over a non-time ORDER BY, 10 
rows per key, HEAP, p=4. Each run in a fresh JVM, variants interleaved. Median 
times:
   
   | | rows in order | rows out of order |
   |---|---|---|
   | master | 147.0 s | 244.0 s |
   | this PR | 157.1 s | 265.4 s |
   | copy only in setAccumulatorOfPrevRow/PrevId | 159.4 s | 258.0 s |
   | no copy at all | 148.1 s | 239.8 s |
   
   So the copy costs 7-9%. Copying only on those two reads saves little: 
nothing in order, about a fifth out of order.
   
   I could skip the copy when every accumulator field is immutable, checked 
once in open(). That covers COUNT/SUM/MIN/MAX/AVG. Want me to add it?
   



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