fix: honor the volatility of aggregate, window and higher-order functions in Expr::is_volatile - #25513
Open
anishmehta24 wants to merge 1 commit into
Open
fix: honor the volatility of aggregate, window and higher-order functions in Expr::is_volatile#25513anishmehta24 wants to merge 1 commit into
Expr::is_volatile#25513anishmehta24 wants to merge 1 commit into
Conversation
…ions in `Expr::is_volatile` `Expr::is_volatile_node` only looked at `Expr::ScalarFunction`, so a volatile `AggregateUDF`, `WindowUDF` or `HigherOrderUDF` looked deterministic to `Expr::is_volatile` and to every optimizer rule built on it (common subexpression elimination, filter and TopK pushdown, the simplifier). The physical `HigherOrderFunctionExpr::is_volatile_node` already checked the signature; the logical `Expr` was the outlier. Closes apache#25504
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25513 +/- ##
==========================================
- Coverage 82.38% 82.38% -0.01%
==========================================
Files 1138 1138
Lines 434313 434421 +108
Branches 434313 434421 +108
==========================================
+ Hits 357805 357879 +74
- Misses 54876 54908 +32
- Partials 21632 21634 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Expr::is_volatileignores the volatility of aggregate, window and higher-order functions #25504.Rationale for this change
Expr::is_volatile_nodeonly matchedExpr::ScalarFunction, soExpr::is_volatilenever saw the volatility that anAggregateUDF,WindowUDForHigherOrderUDFdeclares in its signature. Every optimizer rule built onis_volatile(common subexpression elimination, filter pushdown, TopK-through-join, the simplifier,is_repeatableinoptimizer::utils) therefore treated a volatile user-defined function of those kinds as deterministic and could deduplicate, move or double-evaluate it. The physicalHigherOrderFunctionExpr::is_volatile_nodealready checks its signature; the logicalExprwas the outlier.What changes are included in this PR?
Expr::is_volatile_nodenow reads the signature volatility ofExpr::ScalarFunction,Expr::AggregateFunction,Expr::WindowFunction(bothWindowFunctionDefinitionvariants, so an aggregate used as a window function keeps its volatility) andExpr::HigherOrderFunction. Every other node is still non-volatile.Expr::is_volatileis unchanged and picks the new cases up throughexists.What is the testing strategy for this PR?
New unit test
expr::test::test_is_volatile_aggregate_window_and_higher_order_funcsindatafusion/expr/src/expr.rs: forImmutable,StableandVolatilesignatures it builds an aggregate, a window aggregate, a window UDF and a higher-order function call and checksis_volatile_node/is_volatile, plus the nestedlit + aggcase. The aggregate/window/HOF assertions fail onmain. All built-in functions in these categories areImmutable, 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