Skip to content

[Python] Fix FnApiRunner merging WindowFns with custom window coders - #41991

Open
raman118 wants to merge 1 commit into
apache:masterfrom
raman118:fix-generic-merging-custom-window-coder
Open

raman118 wants to merge 1 commit into
apache:masterfrom
raman118:fix-generic-merging-custom-window-coder

Conversation

@raman118

@raman118 raman118 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #24679

The FnApiRunner (the Python direct runner) keeps windows whose coder it doesn't understand as opaque, timestamp-prefixed bytes (_OpaqueWindow). For merging WindowFns it doesn't know, it calls back into the SDK through GenericMergingWindowFn. That code encoded the windows with the user's window coder instead of the opaque one, so grouping by a merging WindowFn with a custom window type failed:

TypeError: Cannot convert _OpaqueWindow to apache_beam.utils.windowed_value._IntervalWindowBase

This is what breaks Nexmark queries 4, 6 and 9: WinningBids uses the merging AuctionOrBidWindowFn with its own AuctionOrBidWindowCoder. The error message is different from the 2022 report (which hit an older code path), but the cause is the same.

Fix: when the window coder isn't one the runner knows, the merge bundle now uses the same wire format as the rest of the runner:

  • The SDK side uses CUSTOM_WINDOW(LENGTH_PREFIX(window_coder)), so the SDK decodes the real windows.
  • The runner side uses TIMESTAMP_PREFIXED_OPAQUE_WINDOW_CODER, so the windows stay opaque.

Windows with known coders, such as IntervalWindow, work as before. To decide which case applies, I moved the existing known-coder-URN logic into TransformContext.known_coder_urns() so translations.py and execution.py share it.

Testing:

  • Added test_custom_merging_window_type, a merging WindowFn over a custom window type and coder. It fails on all 5 FnApiRunnerTest variants without the fix and passes with it.
  • pytest apache_beam/runners/portability/fn_api_runner/: 499 passed, 81 skipped.
  • Ran WinningBids on a small set of auction and bid events. It failed before the fix and now returns the expected winning bid.
  • Formatted with yapf 0.43.0.

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

🤖 Generated with Claude Code

The FnApiRunner holds windows whose coder it doesn't understand as opaque,
timestamp-prefixed bytes. GenericMergingWindowFn, which calls back into the
SDK to merge such windows, encoded them with the user's window coder instead,
so grouping by a merging WindowFn with a custom window type failed with
"Cannot convert _OpaqueWindow to ...". This broke Nexmark queries 4, 6 and 9.

Exchange the windows with the SDK in the same timestamp-prefixed format the
runner uses elsewhere: the SDK decodes the real windows, and the runner keeps
them opaque.

Fixes apache#24679

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm added as fallback since no labels match configuration
Backup reviewer: tvalentyn (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python Nexmark Query 4,6,9 is broken 'bytes' object has no attribute 'end'

1 participant