findepi commented on code in PR #17351:
URL: https://github.com/apache/datafusion/pull/17351#discussion_r2324687435


##########
datafusion/physical-expr-common/src/physical_expr.rs:
##########
@@ -560,3 +573,26 @@ pub fn is_dynamic_physical_expr(expr: &Arc<dyn 
PhysicalExpr>) -> bool {
     // If the generation is non-zero, then this `PhysicalExpr` is dynamic.
     snapshot_generation(expr) != 0
 }
+
+/// Returns true if the expression is volatile, i.e. whether it can return 
different
+/// results when evaluated multiple times with the same input.
+///
+/// For example the function call `RANDOM()` is volatile as each call will
+/// return a different value.
+///
+/// This method recursively checks if any sub-expression is volatile, for 
example
+/// `1 + RANDOM()` will return `true`.
+pub fn is_volatile(expr: &Arc<dyn PhysicalExpr>) -> bool {
+    let mut is_volatile = expr.is_volatile_node();
+    expr.apply(|e| {
+        is_volatile = is_volatile || e.is_volatile_node();

Review Comment:
   I thought about sth like
   ```rust
   pub fn is_volatile(expr: &Arc<dyn PhysicalExpr>) -> bool {
       if expr.is_volatile_node() {
           return true;
       }
       let mut is_volatile = false;
       expr.apply(|e| {
           if e.is_volatile_node() {
               is_volatile = true;
               Ok(TreeNodeRecursion::Stop)
           } else {
               Ok(TreeNodeRecursion::Continue)
           }
       })
       .expect("infallible closure should not fail");
       is_volatile
   }
   ```



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to