Skip to content

Commit

Permalink
Improve volatile expression handling in CommonSubexprEliminate rule
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-toth committed Jul 4, 2024
1 parent 6e63748 commit 6532b97
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 87 deletions.
103 changes: 52 additions & 51 deletions datafusion-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,12 +1413,16 @@ impl Expr {
.unwrap()
}

/// Returns true if the expression node is volatile, i.e. whether it can return
/// different results when evaluated multiple times with the same input.
pub fn is_volatile_node(&self) -> bool {
matches!(self, Expr::ScalarFunction(func) if func.func.signature().volatility == Volatility::Volatile)
}

/// Returns true if the expression is volatile, i.e. whether it can return different
/// results when evaluated multiple times with the same input.
pub fn is_volatile(&self) -> Result<bool> {
self.exists(|expr| {
Ok(matches!(expr, Expr::ScalarFunction(func) if func.func.signature().volatility == Volatility::Volatile ))
})
self.exists(|expr| Ok(expr.is_volatile_node()))
}

/// Recursively find all [`Expr::Placeholder`] expressions, and
Expand Down
1 change: 1 addition & 0 deletions datafusion/optimizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async-trait = { workspace = true }
chrono = { workspace = true }
datafusion-common = { workspace = true, default-features = true }
datafusion-expr = { workspace = true }
datafusion-functions = { workspace = true }
datafusion-physical-expr = { workspace = true }
hashbrown = { workspace = true }
indexmap = { workspace = true }
Expand Down
Loading

0 comments on commit 6532b97

Please sign in to comment.