Source.combine single source with type-transforming fan-in strategies#2746
Merged
Conversation
…in strategies (apache#2723) (apache#2726) Motivation: Source.combine with a single source bypassed the fan-in strategy using an unsafe asInstanceOf cast. This worked for type-preserving strategies like Merge (T → T), but silently produced incorrect results for type-transforming strategies like MergeLatest (T → List[T]). For example: Source.combine(Seq(Source.single(1)))(MergeLatest(_)) emitted 1 instead of List(1) Modification: - Introduce TypePreservingFanIn marker trait for fan-in stages where T == U AND single-input behavior is a no-op pass-through (Merge, Concat, Interleave, MergePrioritized, OrElse) - MergeSequence intentionally NOT marked: despite being T → T, it validates sequence ordering (not a pure pass-through) - Source.combine single-source case: check TypePreservingFanIn trait before bypassing. Strategies without the trait are routed through the fan-in graph. - Relax Concat, Interleave, MergeSequence to accept inputPorts >= 1 (was > 1). This eliminates the need for a try-catch fallback in Source.combine and allows these stages to be used directly with a single input. - Use Source.fromGraph for non-Source Graph inputs safety - Add 14 regression tests (12 Scala + 1 Java + MergeSequence validation) Result: - MergeLatest/ZipWithN correctly apply their transformation even for single source - Merge/Concat/Interleave correctly bypass (type-preserving optimization) - MergeSequence correctly validates sequences even for single source - Unknown/third-party strategies default to routing through the fan-in graph (safe default for strategies that may transform types) - Binary compatibility maintained (verified via MiMa) References: - apache#2723 - apache#2726
He-Pin
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cherry pick 566a347 #2723 #2726