Weijun-H commented on code in PR #11542: URL: https://github.com/apache/datafusion/pull/11542#discussion_r1685875278
########## datafusion/expr/src/expr_schema.rs: ########## @@ -112,7 +112,22 @@ impl ExprSchemable for Expr { Expr::OuterReferenceColumn(ty, _) => Ok(ty.clone()), Expr::ScalarVariable(ty, _) => Ok(ty.clone()), Expr::Literal(l) => Ok(l.data_type()), - Expr::Case(case) => case.when_then_expr[0].1.get_type(schema), + // Expr::Case(case) => case.when_then_expr[0].1.get_type(schema), + Expr::Case(case) => { + let then_type = case.when_then_expr[0].1.get_type(schema)?; + if !then_type.is_null() { + return Ok(then_type); + } + + let else_type = case + .else_expr + .as_ref() + .map_or(Ok(DataType::Null), |e| e.get_type(schema))?; + if !else_type.is_null() { + return Ok(else_type); + } + Ok(DataType::Int64) Review Comment: Current implementation will return the first non-NULL type among the then and else expressions. ``` shell > select arrow_typeof(CASE data WHEN 1 THEN NULL WHEN 2 THEN 'FOO' ELSE NULL END )from example; +------------------------------------------------------------------------------------------------------+ | arrow_typeof(CASE example.data WHEN Int64(1) THEN NULL WHEN Int64(2) THEN Utf8("FOO") ELSE NULL END) | +------------------------------------------------------------------------------------------------------+ | Utf8 | | Utf8 | | Utf8 | | Utf8 | +------------------------------------------------------------------------------------------------------+ ``` -- 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