anishmehta24 opened a new pull request, #25513: URL: https://github.com/apache/datafusion/pull/25513
## Which issue does this PR close? - Closes #25504. ## Rationale for this change `Expr::is_volatile_node` only matched `Expr::ScalarFunction`, so `Expr::is_volatile` never saw the volatility that an `AggregateUDF`, `WindowUDF` or `HigherOrderUDF` declares in its signature. Every optimizer rule built on `is_volatile` (common subexpression elimination, filter pushdown, TopK-through-join, the simplifier, `is_repeatable` in `optimizer::utils`) therefore treated a volatile user-defined function of those kinds as deterministic and could deduplicate, move or double-evaluate it. The physical `HigherOrderFunctionExpr::is_volatile_node` already checks its signature; the logical `Expr` was the outlier. ## What changes are included in this PR? `Expr::is_volatile_node` now reads the signature volatility of `Expr::ScalarFunction`, `Expr::AggregateFunction`, `Expr::WindowFunction` (both `WindowFunctionDefinition` variants, so an aggregate used as a window function keeps its volatility) and `Expr::HigherOrderFunction`. Every other node is still non-volatile. `Expr::is_volatile` is unchanged and picks the new cases up through `exists`. ## What is the testing strategy for this PR? New unit test `expr::test::test_is_volatile_aggregate_window_and_higher_order_funcs` in `datafusion/expr/src/expr.rs`: for `Immutable`, `Stable` and `Volatile` signatures it builds an aggregate, a window aggregate, a window UDF and a higher-order function call and checks `is_volatile_node` / `is_volatile`, plus the nested `lit + agg` case. The aggregate/window/HOF assertions fail on `main`. All built-in functions in these categories are `Immutable`, so the existing sqllogictests are unaffected. ## Are there any user-facing changes? Optimizer rules now leave volatile user-defined aggregate, window and higher-order functions alone, as they already did for volatile scalar functions. No API change. 🤖 Generated with [Claude Code](https://claude.com/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]
