jonahgao commented on code in PR #11542:
URL: https://github.com/apache/datafusion/pull/11542#discussion_r1685744627


##########
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:
   Although I think returning `DataType::Int64` can make it work fine, because 
after type coercion it always returns `then_type`. But it is still strange, the 
type of `CASE data WHEN 1 THEN NULL WHEN 2 THEN 'FOO' ELSE NULL END` is  
`DataType::Int64`.
   
   How about returning the first non-NULL type among the `then`  and `else` 
expressions?



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