EnricoMi opened a new pull request, #37551: URL: https://github.com/apache/spark/pull/37551
### What changes were proposed in this pull request? This adds sorted versions of `ds.groupByKey(…).flatMapGroups(…)` and `ds.groupByKey(…).cogroup(…)`. ### Why are the changes needed? The existing methods `flatMapGroups` and `cogroup` provide an iterator of rows for each group key. If user code requires those rows in a particular order, that iterator would have to be sorted first, which is against the idea of an iterator in the first place. Methods `flatMapGroups` and `cogroup` have the great advantage that they work with groups that are too large to fit into memory of one executor. Sorting them in the user function breaks this property. [org.apache.spark.sql.KeyValueGroupedDataset](https://github.com/apache/spark/blob/47485a3c2df3201c838b939e82d5b26332e2d858/sql/core/src/main/scala/org/apache/spark/sql/KeyValueGroupedDataset.scala#L134-L137): > Internally, the implementation will spill to disk if any given group is too large to fit into > memory. However, users must take care to avoid materializing the whole iterator for a group > (for example, by calling `toList`) unless they are sure that this is possible given the memory > constraints of their cluster. The implementations of `KeyValueGroupedDataset.flatMapGroups` and `KeyValueGroupedDataset.cogroup` already sort each partition according to the group key. By additionally sorting by some data columns, the iterator can be guaranteed to provide some order. ### Does this PR introduce _any_ user-facing change? This adds `KeyValueGroupedDataset.flatMapSortedGroups` and `KeyValueGroupedDataset.cogroupSorted`. ### How was this patch tested? These tests have been added: - `DatasetSuite."groupBy function, flatMapSorted by func"` - `DatasetSuite."groupBy function, flatMapSorted by expr"` - `DatasetSuite."cogroup sorted"` -- 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]
