Skip to content

[Flink] Skip pre-combine step for batch GroupByKey - #41908

Draft
pkuzmickas wants to merge 1 commit into
apache:masterfrom
pkuzmickas:flink-skip-gbk-precombine
Draft

pkuzmickas wants to merge 1 commit into
apache:masterfrom
pkuzmickas:flink-skip-gbk-precombine

Conversation

@pkuzmickas

Copy link
Copy Markdown
Contributor

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

Co-Authored-By: Xirp Agent (gemini-4-neon) <xirp-agent@users.noreply.ghe.spotify.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant