ygf11 commented on code in PR #3758:
URL: https://github.com/apache/arrow-datafusion/pull/3758#discussion_r990602856


##########
datafusion/optimizer/src/expr_simplifier.rs:
##########
@@ -76,24 +96,181 @@ impl ExprSimplifiable for Expr {
     ///   }
     /// }
     ///
+    /// // Create the simplifier
+    /// let simplifier = ExprSimplifier::new(Info::default());
+    ///
     /// // b < 2
     /// let b_lt_2 = col("b").gt(lit(2));
     ///
     /// // (b < 2) OR (b < 2)
     /// let expr = b_lt_2.clone().or(b_lt_2.clone());
     ///
     /// // (b < 2) OR (b < 2) --> (b < 2)
-    /// let expr = expr.simplify(&Info::default()).unwrap();
+    /// let expr = simplifier.simplify(expr).unwrap();
     /// assert_eq!(expr, b_lt_2);
     /// ```
-    fn simplify<S: SimplifyInfo>(self, info: &S) -> Result<Self> {
-        let mut rewriter = Simplifier::new(info);
-        let mut const_evaluator = 
ConstEvaluator::try_new(info.execution_props())?;
+    pub fn simplify(&self, expr: Expr) -> Result<Expr> {
+        let mut rewriter = Simplifier::new(&self.info);
+        let mut const_evaluator = 
ConstEvaluator::try_new(self.info.execution_props())?;
 
         // TODO iterate until no changes are made during rewrite
         // (evaluating constants can enable new simplifications and
         // simplifications can enable new constant evaluation)
         // https://github.com/apache/arrow-datafusion/issues/1160
-        self.rewrite(&mut const_evaluator)?.rewrite(&mut rewriter)
+        expr.rewrite(&mut const_evaluator)?.rewrite(&mut rewriter)
+    }
+
+    /// Apply type coercion to an [`Expr`] so that it can be
+    /// evaluated as a 
[`PhysicalExpr`](datafusion_physical_expr::PhysicalExpr).
+    ///
+    /// See the [type coercion module](datafusion_expr::type_coercion)
+    /// documentation for more details on type coercion
+    ///
+    // Would be nice if this API could use the SimplifyInfo
+    // rather than creating an DFSchemaRef coerces rather than doing
+    // it manually.
+    // TODO ticekt
+    pub fn coerce(&self, expr: Expr, schema: DFSchemaRef) -> Result<Expr> {

Review Comment:
   TODO ticekt, typo?



-- 
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...@arrow.apache.org

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

Reply via email to