Repository navigation
[Go SDK] Fix generic registration of anonymous struct types - #40649
Thanatos9404 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR resolves a panic during generic registration (register.Function*, register.DoFn*, register.Combiner*) when functions or methods accept or return anonymous struct types. By introducing registerStructType, unnamed structs are skipped for runtime.RegisterType (which requires a type key) while still being registered with schema.RegisterType so row schemas and nested named structs are properly mapped on workers.
🔍 General Feedback
- The changes in
register.tmpland the regeneratedregister.goare clean, minimal, and accurately target the root cause (#21789). - Re-enabling
register.Function1x1(castFn)inbigquery_test.goand the new unit tests inregister_test.gothoroughly cover parameter, return, and DoFn registration paths.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping for label go. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40649 +/- ##
===========================================
- Coverage 80.04% 56.41% -23.64%
===========================================
Files 490 871 +381
Lines 82916 154091 +71175
===========================================
+ Hits 66373 86923 +20550
- Misses 16543 65314 +48771
- Partials 0 1854 +1854
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Generic registration registers every struct type that a function or method takes or returns, with both the runtime type registry and the schema registry. runtime.RegisterType panics for unnamed types, so generic registration could not be used for a function with an anonymous struct parameter, and it stopped before the caller and struct wrappers were set up. registerMethodTypes now adds a struct type to the runtime type registry only when it has a type key, and still adds every struct type to the schema registry, which maps a row schema back to the user's Go type on the worker. graphx already encodes types without a type key field by field. This also enables the castFn registration in the BigQuery integration test that was waiting on this issue. Fixes apache#21789
5786fd5 to
7241c9b
Compare
Fixes #21789
The generic registration functions (
register.Function*,register.DoFn*andregister.Combiner*) pass every struct type a function takes or returns toruntime.RegisterType, which panics for unnamed types. So a function with an anonymous struct parameter panicked ininit()and couldn't use generic registration at all.registerMethodTypesnow adds a struct type to the runtime registry only when it has a type key, and still adds every struct type to the schema registry, which the worker needs to map a row back to the user's Go type. The change is inregister.tmpl, andregister.gowas regenerated withgo generate. An unnamed struct that can't be converted to a schema now fails inbeam.Init, like a named one, instead of panicking earlier.I also enabled the
register.Function1x1(castFn)call in the BigQuery xlang integration test that was waiting on this. I only checked that its test binary now initialises.Tests: three new tests register functions and a DoFn with anonymous struct parameters or return types. All three fail on master with the panic and pass with this change.
CHANGES.mdis updated under Bugfixes for 2.78.0.