Skip to content
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

Merged
merged 1 commit into from
Mar 26, 2024
Merged

Expr to Sql : Case #9798

merged 1 commit into from
Mar 26, 2024

Conversation

yyy1000
Copy link
Contributor

@yyy1000 yyy1000 commented Mar 25, 2024

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?

@github-actions github-actions bot added the sql SQL Planner label 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<_>>>()?;
Copy link
Contributor Author

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

  1. unzip, but I got two vec which consist of Result<Expr> but not Expr
  2. match, got type incompatible error 🥲
  3. collect, but don't know how to collect a (Result<Expr>, Result<Expr>)

Copy link
Contributor

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)?);
                }

Copy link
Contributor Author

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"#),
Copy link
Contributor Author

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.

Copy link
Contributor

@alamb alamb left a 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.

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<_>>>()?;
Copy link
Contributor

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)?);
                }

@alamb alamb merged commit 349c586 into apache:main Mar 26, 2024
23 checks passed
@yyy1000 yyy1000 deleted the expr-sql branch March 26, 2024 02:53
Lordworms pushed a commit to Lordworms/arrow-datafusion that referenced this pull request Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants