charlhhhh opened a new pull request, #60148:
URL: https://github.com/apache/spark/pull/60148

   ### What changes were proposed in this pull request?
   
   `FromProtobuf.replacement` and `ToProtobuf.replacement` now evaluate
   `options.freshCopyIfContainsStatefulExpression()` instead of `options`.
   
   ### Why are the changes needed?
   
   The options argument (e.g. `map('mode', 'PERMISSIVE')`) is a stateful 
`CreateMap` with a single
   `ArrayBasedMapBuilder`. Canonicalization renumbers attribute ids, so each 
canonicalization creates
   a new `FromProtobuf`/`ToProtobuf` copy, but all copies share the unchanged 
options child, and the
   `replacement` lazy val only locks its own copy. Concurrent canonicalizations 
of one plan (for
   example, `CacheManager` re-caching while several queries write tables at the 
same time) therefore
   evaluate the same `CreateMap` concurrently and race on its builder, failing 
with
   `IllegalArgumentException: requirement failed` from `ArrayBasedMapData` or 
`DUPLICATED_MAP_KEY`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No, other than fixing the failures above.
   
   ### How was this patch tested?
   
   New tests in `ProtobufFunctionsSuite`, for both `from_protobuf` and 
`to_protobuf`:
   - overlapping canonicalization: one evaluation of the options is paused 
halfway while a second
     canonicalization of the same expression runs. Before this fix, the second 
one failed with
     `DUPLICATED_MAP_KEY`; now both return the expected options.
   - failed evaluation: one evaluation of the options fails halfway. Before 
this fix, the half-built
     map stayed in the shared `CreateMap`, so retrying the same expression 
failed with
     `DUPLICATED_MAP_KEY`; now each evaluation uses a fresh copy, so the retry 
returns the expected
     options.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Initial draft authored with Claude Code.
   
   Generated-by: Claude Code (Claude Opus 5.5)
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to