-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Expr to Sql : Case #9798
Expr to Sql : Case #9798
Conversation
let conditions = when_then_expr | ||
.iter() | ||
.map(|(w, _)| self.expr_to_sql(w)) | ||
.collect::<Result<Vec<_>>>()?; | ||
let results = when_then_expr | ||
.iter() | ||
.map(|(_, t)| self.expr_to_sql(t)) | ||
.collect::<Result<Vec<_>>>()?; |
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'm trying to make these two iterations to one, but I failed.
I tried
unzip
, but I got two vec which consist ofResult<Expr>
but notExpr
match
, got type incompatible error 🥲collect
, but don't know how to collect a(Result<Expr>, Result<Expr>)
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 likewise tried to use izip
and came up with this, which wasn't particularly nice
let (conditions, results): (Vec<_>, Vec<_>) = when_then_expr
.iter()
.map(|(w, t)| (self.expr_to_sql(w), self.expr_to_sql(t)))
.unzip();
let conditions = conditions.into_iter().collect::<Result<Vec<_>>>()?;
let results = results.into_iter().collect::<Result<Vec<_>>>()?;
This is the best I could come up with but I am not sure how much better it is:
let mut conditions = vec![];
let mut results = vec[]!;
for (w, t) in when_then_expr {
conditions.push(self.expr_to_sql(w)?);
results.push(self.expr_to_sql(t)?);
}
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.
Yeah, I also tried two pushes before but I removed it for declaring two mut vec 😆
@@ -698,17 +733,17 @@ mod tests { | |||
}), | |||
"COUNT(DISTINCT *)", | |||
), | |||
(Expr::IsNotNull(Box::new(col("a"))), r#""a" IS NOT NULL"#), | |||
(col("a").is_not_null(), r#""a" IS NOT NULL"#), |
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 also changed some of these tests to make them looks concise.
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 @yyy1000 -- thank you for the contribution.
let conditions = when_then_expr | ||
.iter() | ||
.map(|(w, _)| self.expr_to_sql(w)) | ||
.collect::<Result<Vec<_>>>()?; | ||
let results = when_then_expr | ||
.iter() | ||
.map(|(_, t)| self.expr_to_sql(t)) | ||
.collect::<Result<Vec<_>>>()?; |
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 likewise tried to use izip
and came up with this, which wasn't particularly nice
let (conditions, results): (Vec<_>, Vec<_>) = when_then_expr
.iter()
.map(|(w, t)| (self.expr_to_sql(w), self.expr_to_sql(t)))
.unzip();
let conditions = conditions.into_iter().collect::<Result<Vec<_>>>()?;
let results = results.into_iter().collect::<Result<Vec<_>>>()?;
This is the best I could come up with but I am not sure how much better it is:
let mut conditions = vec![];
let mut results = vec[]!;
for (w, t) in when_then_expr {
conditions.push(self.expr_to_sql(w)?);
results.push(self.expr_to_sql(t)?);
}
Which issue does this PR close?
Related #9726.
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?