jayzhan211 commented on code in PR #10386:
URL: https://github.com/apache/datafusion/pull/10386#discussion_r1592084830


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1670,17 +1734,106 @@ fn inlist_except(mut l1: InList, l2: InList) -> 
Result<Expr> {
     Ok(Expr::InList(l1))
 }
 
+pub struct RewriteCycle {
+    consecutive_unchanged_count: usize,
+    total_iterations: usize,
+    num_rewriters: usize,
+}
+pub type RewriteCycleResult = ControlFlow<Result<Expr>, Expr>;
+
+impl RewriteCycle {
+    fn new() -> Self {
+        RewriteCycle {
+            // use usize::MAX as default to avoid checking null in is_done() 
comparison
+            // real value is set later by record_num_rewriters
+            num_rewriters: usize::MAX,
+            consecutive_unchanged_count: 0,
+            total_iterations: 0,
+        }
+    }
+
+    pub fn completed_cycles(&self) -> usize {
+        // default value indicates we have not completed a cycle
+        if self.num_rewriters == usize::MAX {
+            0
+        } else {
+            self.total_iterations / self.num_rewriters
+        }
+    }
+
+    pub fn total_iterations(&self) -> usize {
+        self.total_iterations
+    }
+
+    fn record_num_rewriters(&mut self) {
+        self.num_rewriters = self.total_iterations;
+    }
+
+    fn is_done(&self) -> bool {
+        self.consecutive_unchanged_count >= self.num_rewriters

Review Comment:
   > if the const evaluator returns false, simpliy could still return true
   
   In this case, `transformed` is true, and we should try another pass.
   
   I think once we found `transformed` is false for every rules, any further 
pass will still remain unchanged, so we can skip it.



-- 
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