pkuzmickas opened a new pull request, #41908:
URL: https://github.com/apache/beam/pull/41908

   Addresses #40607.
   
   In batch on the DataStream translation path (always on the Flink 2 runner, 
and with `--useDataStreamForBatch` on Flink 1), 
`FlinkStreamingAggregationsTranslators.batchGroupByKey` routes every 
`GroupByKey` through `PartialReduceBundleOperator` with 
`ConcatenateAsIterable`, followed by a `FlattenIterable` flatMap after the 
shuffle.
   
   Unlike `Combine.perKey`, grouping values into an `Iterable` cannot reduce 
payload bytes: every input value still crosses the shuffle verbatim, with extra 
`IterableCoder` framing and `O(n^2)` list copying in 
`ConcatenateAsIterable#addInput` when keys repeat in a bundle. Worse, in 
`CoGroupByKey` the input to `GroupByKey` is a `union` of multiple branches, so 
Flink cannot chain `PartialReduceBundleOperator` onto its upstream inputs and 
inserts an extra blocking-shuffle stage. In a production Scio batch job joining 
~2.2B records (~83 TB), those redundant `Combine:` stages wrote and re-read 
~102 TB with 0.04% record reduction, adding ~15 minutes to wall-clock time.
   
   ## What changes
   
   - Translate `batchGroupByKey` directly as 
`inputDataStream.keyBy(keySelector)` followed by the final grouping operator 
(`SortedBatchCombineOperator` or `WindowDoFnOperator`), removing 
`ConcatenateAsIterable`, `FlattenIterable`, and the 
`PartialReduceBundleOperator` stage for `GroupByKey`.
   - Preserve `--lazyBatchGroupingInputs` by setting `withLazyKvValues()` only 
on the `KeyedStream`'s `PartitionTransformation` output type, leaving upstream 
streams and peer consumers unchanged while keeping lazy deserialization into 
`LazyKvWindowedValue` on the grouping operator's input.
   - Add translation and end-to-end batch execution tests in 
`FlinkStreamingAggregationsTranslatorsTest` covering `GroupByKey` (global and 
fixed windows), `CoGroupByKey`, and lazy input serialization.
   
   🤖 Generated with [Xirp Agent](https://spotify.ghe.com/xirp-org/agent)


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