jayzhan211 commented on PR #14283: URL: https://github.com/apache/datafusion/pull/14283#issuecomment-2614154584
The function `coerce_types` is used exclusively within function handling. For case expressions, `coerce_types` is not utilized. Instead, the function `get_coerce_type_for_case_expression` is used, which internally relies on `comparison_coercion` as the actual coercion function ```rust pub fn get_coerce_type_for_case_expression( when_or_then_types: &[DataType], case_or_else_type: Option<&DataType>, ) -> Option<DataType> { let case_or_else_type = match case_or_else_type { None => when_or_then_types[0].clone(), Some(data_type) => data_type.clone(), }; when_or_then_types .iter() .try_fold(case_or_else_type, |left_type, right_type| { // TODO: now just use the `equal` coercion rule for case when. If find the issue, and // refactor again. comparison_coercion(&left_type, right_type) }) } ``` Therefore, I think Comet also need to applies such coercion before calling `CaseExpr::try_new` In datafusion, `Null` is coerced to `Int32(Null)` in `type_coercion`. ``` [2025-01-26T00:36:20Z DEBUG datafusion_optimizer::utils] resolve_grouping_function: Projection: CASE WHEN foo.a IS NULL THEN NULL ELSE foo.b END TableScan: foo [2025-01-26T00:36:20Z DEBUG datafusion_optimizer::utils] type_coercion: Projection: CASE WHEN foo.a IS NULL THEN CAST(NULL AS Int32) ELSE foo.b END TableScan: foo [2025-01-26T00:36:20Z DEBUG datafusion_optimizer::utils] count_wildcard_rule: Projection: CASE WHEN foo.a IS NULL THEN CAST(NULL AS Int32) ELSE foo.b END TableScan: foo ``` -- 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