Skip to content

Expr to Sql : Case - #9798

Merged
alamb merged 1 commit into
apache:mainfrom
yyy1000:expr-sql
Mar 26, 2024
Merged

alamb merged 1 commit into
apache:mainfrom
yyy1000:expr-sql

Conversation

@yyy1000

@yyy1000 yyy1000 commented Mar 25, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 😆

"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
Copy Markdown
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.

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
@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