Jefffrey commented on code in PR #5820:
URL: https://github.com/apache/arrow-datafusion/pull/5820#discussion_r1155097167
##########
datafusion/optimizer/src/type_coercion.rs:
##########
@@ -330,8 +330,35 @@ impl TreeNodeRewriter for TypeCoercionRewriter {
}
}
Expr::Case(case) => {
- // all the result of then and else should be convert to a
common data type,
- // if they can be coercible to a common data type, return
error.
+ // Given expressions like:
+ //
+ // CASE a1
+ // WHEN a2 THEN b1
+ // WHEN a3 THEN b2
+ // ELSE b3
+ // END
+ //
+ // or:
+ //
+ // CASE
+ // WHEN x1 THEN b1
+ // WHEN x2 THEN b2
+ // ELSE b3
+ // END
+ //
+ // Then all aN (a1, a2, a3) must be converted to a common data
type in the first example
+ // (case-when expression coercion)
+ //
+ // And all bN (b1, b2, b3) must be converted to a common data
type in both examples
+ // (then-else expression coercion)
+ //
+ // If either fail to find a common data type, will return error
+
+ // prepare types
+ let case_type = match &case.expr {
+ None => Ok(None),
+ Some(expr) => expr.get_type(&self.schema).map(Some),
+ }?;
Review Comment:
Thanks that does look cleaner, will apply it
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]