-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: CASE with NULL #11542
fix: CASE with NULL #11542
Conversation
datafusion/expr/src/expr_schema.rs
Outdated
.map_or(Ok(DataType::Null), |e| e.get_type(schema))?; | ||
|
||
match (then_type.clone(), else_type.clone()) { | ||
(DataType::Null, DataType::Null) => Ok(DataType::Int64), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be a problem with the following expression.
CASE data WHEN 1 THEN NULL WHEN 2 THEN 3.3 ELSE NULL END;
Its type being float would be more reasonable.
Another more general fix might be to ensure that type coercion has already been performed before calling get_type
, but I am not sure if that can be achieved. Therefore, the current solution is okay for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test for it
for (_, then_expr) in &case.when_then_expr { | ||
let then_type = then_expr.get_type(schema)?; | ||
if !then_type.is_null() { | ||
return Ok(then_type); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return first non-null then type here @jonahgao
Co-authored-by: Jonah Gao <[email protected]>
Co-authored-by: Jonah Gao <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍, thanks @Weijun-H
* fix: CASE with NULL * chore: Add tests * chore * chore: Fix CI * chore: Support all types are NULL * chore: Fix CI * chore: add more tests * fix: Return first non-null type in then exprs * chore: Fix CI * Update datafusion/expr/src/expr_schema.rs Co-authored-by: Jonah Gao <[email protected]> * Update datafusion/expr/src/expr_schema.rs Co-authored-by: Jonah Gao <[email protected]> --------- Co-authored-by: Jonah Gao <[email protected]>
Which issue does this PR close?
Closes #11258
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?