adriangb commented on PR #19130: URL: https://github.com/apache/datafusion/pull/19130#issuecomment-3621848790
@alamb I wonder if there could be any way to express that an expression is "constant" in terms of volatility? We currently have `fn is_volatile(expr: &Arc<dyn PhysicalExpression>) -> bool`, but that doesn't tell you if it's a "stable" expression (like `column > 123`) or a "constant" expression (`456 > 123`). Looking at the logical expression const evaluator it seems like it does manual matching: https://github.com/apache/datafusion/blob/deaccb784ee1223bf9eed36562c5775aaedebc6b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs#L637-L682. It looks like we have a `Volatility` targeted at functions: https://github.com/apache/datafusion/blob/c479deeb668cc444936bbfa66100aef9b2013b2e/datafusion/expr-common/src/signature.rs#L53-L85 But it does not have a "constant" option (nor would that really make sense for a function). `Constant` is not the same as immutable, as per the definition above `Immutable`: > Always returns the same output when given the same input. `Constant` would be: > Always returns the same output regardless of the input. (Generally because it has no input but I guess you could have an expression that takes an input but returns a constant / ignores the input?) Which makes me wonder if it wouldn't make sense to an enum along the lines of: ```rust pub enum ExpressionVolatility { Constant, Immutable, Stable, Volatile, } ``` And augment `PhysicalExpression` and `Expr` with methods to calculate the volatility. -- 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]
