Repository navigation
Expr to Sql : Case - #9798
Merged
Merged
Expr to Sql : Case#9798
Conversation
yyy1000
commented
Mar 25, 2024
Comment on lines
+119
to
+126
| 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<_>>>()?; |
Contributor
Author
There was a problem hiding this comment.
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 notExprmatch, got type incompatible error 🥲collect, but don't know how to collect a(Result<Expr>, Result<Expr>)
Contributor
There was a problem hiding this comment.
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)?);
}
Contributor
Author
There was a problem hiding this comment.
Yeah, I also tried two pushes before but I removed it for declaring two mut vec 😆
| "COUNT(DISTINCT *)", | ||
| ), | ||
| (Expr::IsNotNull(Box::new(col("a"))), r#""a" IS NOT NULL"#), | ||
| (col("a").is_not_null(), r#""a" IS NOT NULL"#), |
Contributor
Author
There was a problem hiding this comment.
I also changed some of these tests to make them looks concise.
alamb
approved these changes
Mar 26, 2024
Comment on lines
+119
to
+126
| 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<_>>>()?; |
Contributor
There was a problem hiding this comment.
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)?);
}
Lordworms
pushed a commit
to Lordworms/arrow-datafusion
that referenced
this pull request
Apr 1, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?