sunchao opened a new pull request, #59996: URL: https://github.com/apache/spark/pull/59996
### What changes were proposed in this pull request? Resolve references to serializer outputs by expression ID before pruning their nested fields. When rebuilding field accesses, use the schema that the serializer actually emits. Preserve the spelling of output columns requested by the query. ### Why are the changes needed? A case-insensitive reference can cause an array index exception during optimization. A serializer can also retain its original struct layout even when a narrower one was requested. In that case a projection can read a sibling of the requested field. For example, the constant-key Dataset query in the regression test returns `map-a` for a request for `map-b`. This correctness fix was identified in the [review of SPARK-60766](https://github.com/apache/spark/pull/59972#discussion_r4433280743) and can be backported independently. ### Does this PR introduce _any_ user-facing change? Yes. Affected typed Dataset projections return the requested fields and preserve their output column names. ### How was this patch tested? Added two constant-selector regressions to `DatasetOptimizationSuite` covering the array error, output naming and the incorrect Map value. The complete suite passed with the changed source on public Spark 4.1.3 test dependencies. Both new tests failed on the unmodified parent optimizer. Changed-file ScalaStyle and `git diff --check` passed. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6) -- 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]
