shehabgamin commented on code in PR #14268: URL: https://github.com/apache/datafusion/pull/14268#discussion_r1929529897
########## datafusion/optimizer/src/analyzer/type_coercion.rs: ########## @@ -2133,4 +2133,77 @@ mod test { assert_analyzed_plan_eq(Arc::new(TypeCoercion::new()), plan, expected)?; Ok(()) } + + /// Create a [`PhysicalExpr`] from an [`Expr`] after applying type coercion. + fn create_physical_expr_with_type_coercion( + expr: Expr, + df_schema: &DFSchema, + ) -> Result<Arc<dyn PhysicalExpr>> { + let props = ExecutionProps::default(); + let coerced_expr = expr + .rewrite(&mut TypeCoercionRewriter::new(df_schema))? + .data; + let physical_expr = datafusion_physical_expr::create_physical_expr( + &coerced_expr, + df_schema, + &props, + )?; + Ok(physical_expr) + } + + fn evaluate_expr_with_array( + expr: Expr, + batch: RecordBatch, + df_schema: &DFSchema, + ) -> Result<ArrayRef> { + let physical_expr = create_physical_expr_with_type_coercion(expr, df_schema)?; + match physical_expr.evaluate(&batch)? { + ColumnarValue::Array(result) => Ok(result), + _ => datafusion_common::internal_err!( + "Expected array result in evaluate_expr_with_array" + ), + } + } + + fn evaluate_expr_with_scalar(expr: Expr) -> Result<ScalarValue> { + let df_schema = DFSchema::empty(); + let physical_expr = create_physical_expr_with_type_coercion(expr, &df_schema)?; + match physical_expr + .evaluate(&RecordBatch::new_empty(Arc::clone(df_schema.inner())))? + { + ColumnarValue::Scalar(result) => Ok(result), + _ => datafusion_common::internal_err!( + "Expected scalar result in evaluate_expr_with_scalar" + ), + } + } + + #[test] + fn test_ascii_expr() -> Result<()> { Review Comment: I would have preferred to place the various UDF tests within their respective files, but I couldn't due to circular dependencies. -- 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