zeruibao commented on code in PR #52391:
URL: https://github.com/apache/spark/pull/52391#discussion_r2396438513


##########
python/pyspark/sql/pandas/serializers.py:
##########
@@ -1630,8 +1633,23 @@ def row_stream():
                         yield (batch_key, row)
 
             for batch_key, group_rows in groupby(row_stream(), key=lambda x: 
x[0]):
-                df = pd.DataFrame([row for _, row in group_rows])
-                yield (batch_key, df)
+                rows = []
+                accumulate_size = 0
+                for _, row in group_rows:
+                    rows.append(row)
+                    # Short circuit batch size calculation if the batch size is
+                    # unlimited as computing batch size is computationally 
expensive.
+                    if self.arrow_max_bytes_per_batch != 2**31 - 1:

Review Comment:
   Since we already leverage the generator-based approach to optimize for 
high-cardinality scenarios, switching to `applyInPandasWithState` would not be 
a trivial change. I would prefer to retaining the current implementation.



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