-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
CaseWhen: coerce the all then and else data type to a common data type #2819
CaseWhen: coerce the all then and else data type to a common data type #2819
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2819 +/- ##
==========================================
+ Coverage 85.18% 85.19% +0.01%
==========================================
Files 275 275
Lines 48564 48634 +70
==========================================
+ Hits 41367 41434 +67
- Misses 7197 7200 +3
Continue to review full report at Codecov.
|
50fd76b
to
00edadf
Compare
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 -- I had some style suggestions but nothing major. Thank you @liukun4515
@@ -76,7 +77,7 @@ impl CaseExpr { | |||
/// Create a new CASE WHEN expression | |||
pub fn try_new( | |||
expr: Option<Arc<dyn PhysicalExpr>>, | |||
when_then_expr: &[WhenThen], | |||
when_then_expr: Vec<WhenThen>, |
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.
👍
Ok(Arc::new(CaseExpr::try_new(expr, when_thens, else_expr)?)) | ||
} | ||
|
||
fn get_case_common_type( | ||
when_thens: &[WhenThen], | ||
else_expr: Option<Arc<dyn PhysicalExpr>>, |
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.
else_expr: Option<Arc<dyn PhysicalExpr>>, | |
else_expr: Option<&PhysicalExpr>, |
I wonder if there is a reason it needs to get a copy, or would a reference work too?
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.
The reference is not work for this.
let left = when_thens | ||
.into_iter() | ||
.map(|(when, then)| { | ||
let then = try_cast(then, input_schema, data_type.clone()).unwrap(); | ||
(when, then) | ||
}) | ||
.collect::<Vec<WhenThen>>(); |
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.
Are we sure this will always return without error (aka that this will not panic)?
Since this function can return an Result
anyways, would it be better to return it. Something like (untested):
let left = when_thens | |
.into_iter() | |
.map(|(when, then)| { | |
let then = try_cast(then, input_schema, data_type.clone()).unwrap(); | |
(when, then) | |
}) | |
.collect::<Vec<WhenThen>>(); | |
let left = when_thens | |
.into_iter() | |
.map(|(when, then)| { | |
let then = try_cast(then, input_schema, data_type.clone())? | |
Ok((when, then)) | |
}) | |
.collect::<Result<Vec<WhenThen>>>()?; |
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.
good catch
let when1 = binary( | ||
col("a", &schema)?, | ||
Operator::Eq, | ||
lit(ScalarValue::Utf8(Some("foo".to_string()))), |
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.
It would be nice if the the lit
in the physical expr could use lit("foo")
as well. But I tried it and it doesn't work
lit(ScalarValue::Utf8(Some("foo".to_string()))), | |
lit("foo"), |
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 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.
I will rebase this pr after #2828 merged
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.
changed the code to use lit("foo")
with merged #2828
00b0c39
to
d50c671
Compare
I accidentally pushed commits to this branch -- I think I have removed them now. My apologies |
Which issue does this PR close?
Closes #2818
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?