tohuya6 opened a new pull request, #23850: URL: https://github.com/apache/datafusion/pull/23850
## Which issue does this PR close? - Closes #23697. ## Rationale for this change `SessionState` registers every UDF under its canonical name and each of its aliases, so a single `Arc` is reachable from multiple keys in the scalar, aggregate, window, and higher-order registries. `SessionStateBuilder::new_from_existing` flattened those registries with `HashMap::into_values()`, which yields the shared `Arc`s duplicated and in non-deterministic iteration order. On `build()` the functions are re-registered last-writer-wins, so which function ends up owning a contested alias depended on HashMap ordering. A user's alias override of a builtin (for example a custom `to_char`) could silently revert — and do so differently from run to run. ## What changes are included in this PR? Reconstruct a faithful registration order instead of relying on HashMap iteration order. Because the registry was produced by some real registration sequence, an order that reproduces it always exists. - Add the `AliasedRegistryEntry` trait and a `deterministic_registration_order` helper. The helper dedups entries by `Arc` identity and topologically sorts them under a single rule — a key's owner must register after every other function that also claims that key by name or alias — breaking ties by canonical name. - Use it for the scalar / aggregate / window / higher-order registries in `new_from_existing`. Any valid order reproduces the exact map, so the roundtrip is now both deterministic and override-preserving. ## Are these changes tested? Yes. New regression tests cover: - an alias override survives the roundtrip on every run, - the alias-chain counterexample from #21262 roundtrips exactly, and - a unit test that the helper's reconstructed order replays to the input map. ## Are there any user-facing changes? No API changes. This fixes a correctness bug: alias overrides now survive `SessionStateBuilder::new_from_existing` deterministically. -- 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]
