charlhhhh opened a new pull request, #60354:
URL: https://github.com/apache/spark/pull/60354
### What changes were proposed in this pull request?
`FromAvro.replacement` and `SchemaOfAvro.replacement` now evaluate
`options.freshCopyIfContainsStatefulExpression()` instead of `options`. This
is the same fix as
SPARK-60945 (#60148) for `from_protobuf`/`to_protobuf`.
### 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 `FromAvro` 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, cache
lookups while several queries run 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`. The builder only resets
after a successful build,
so a failed evaluation leaves its entries behind and later evaluations of
the same expression keep
failing with `DUPLICATED_MAP_KEY`. With
`spark.sql.mapKeyDedupPolicy=LAST_WIN`, the race can
instead silently drop options.
`SchemaOfAvro` has no attribute input, so canonicalization does not copy it,
but it evaluates its
options the same way and a failed evaluation can leave a partial map behind,
so it gets the same
change.
### Does this PR introduce _any_ user-facing change?
Yes. This fixes the failures and missing options caused by concurrent
evaluation of the
`from_avro` options.
### How was this patch tested?
New tests in `AvroFunctionsSuite`:
- overlapping canonicalization of `from_avro` under both `EXCEPTION` and
`LAST_WIN`: one options
evaluation pauses after inserting its first key while a second
canonicalization runs. Before
this fix, `EXCEPTION` produced `DUPLICATED_MAP_KEY` and `LAST_WIN`
returned options missing the
first key; both evaluations now return the complete options.
- failed evaluation, for both `from_avro` and `schema_of_avro`: one
evaluation of the options fails
halfway. Before this fix, retrying the same expression failed with
`DUPLICATED_MAP_KEY`; it now
returns the expected options.
Without the fix, all four cases fail; with it, they pass. `avro/scalastyle`,
`avro/Test/scalastyle`
and `catalyst/scalastyle` report no errors.
### Was this patch authored or co-authored using generative AI tooling?
Initial draft authored with Claude Code.
--
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]