HyukjinKwon commented on code in PR #60543:
URL: https://github.com/apache/spark/pull/60543#discussion_r4581887029


##########
python/pyspark/sql/tests/arrow/test_arrow_python_aggregator.py:
##########
@@ -401,6 +439,34 @@ def test_window_bounded_preceding_frame(self):
         for r, e in zip(result, expected):
             self.assertAlmostEqual(r["m"], e["m"], places=6)
 
+    def test_window_growing_frame_with_in_place_buffer(self):
+        # ``reduce`` may update its buffer in place, and over a frame whose 
lower bound stays fixed
+        # later rows keep reducing into the buffer that earlier rows were 
finished from. Each row
+        # must still get its own frame's value, also when ``finish`` returns 
the buffer's list
+        # itself or nests it in a struct.
+        df = self._data()
+        ordered = Window.partitionBy("k").orderBy("v")
+        frames = {

Review Comment:
   Good catch. In d6f5cee, `test_window_frames_with_in_place_buffer` uses data 
with ties and nulls in `v` and covers four frames:
   - the default frame, where peers share a frame, so `finish` runs again on a 
buffer that did not grow;
   - `rowsBetween(unboundedPreceding, currentRow)`;
   - `rangeBetween(unboundedPreceding, 1)`;
   - `rowsBetween(-2, currentRow)`.
   
   Each frame also checks string and binary results from a `bytearray`, next to 
the list and struct ones. ROWS frames break ties by `id`, so every frame is 
deterministic. All four frames fail before this PR and at ae2290f (on the 
string results), and pass now. I also added handler-level tests in 
`test_arrow_eval_type_handlers.py`.



##########
python/pyspark/sql/aggregator.py:
##########
@@ -126,7 +136,11 @@ def merge(self, buffer1: Tuple[Any, ...], buffer2: 
Tuple[Any, ...]) -> Tuple[Any
 
     @abstractmethod
     def finish(self, buffer: Tuple[Any, ...]) -> Any:
-        """Produce the output value from the final merged buffer."""
+        """Produce the output value from the final merged buffer.
+
+        It must not modify ``buffer``: over a window, it is called once per 
row on a buffer that

Review Comment:
   Thanks, fixed in d6f5cee. The `Aggregator` docs now say that an unbounded 
frame is folded once and its `finish` value is repeated for every row. The 
first line of `finish` no longer says "final merged buffer". The comments in 
`PythonRunner.scala`, `util.py`, `windowExpressions.scala` and the handler now 
say that frame bounds are sent only for bounded frames.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to