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

feat(unparser): adding alias for table scan filter in sql unparser #12453

Merged
merged 1 commit into from
Sep 15, 2024

Conversation

Lordworms
Copy link
Contributor

Which issue does this PR close?

Closes #12368

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 sql SQL Planner core Core DataFusion crate labels Sep 13, 2024
Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Lordworms working on this. Overall looks good to me. Just leave some suggestions.

Comment on lines 699 to 703
fn test_alias_pushdown() -> Result<()> {
let schema = Schema::new(vec![
Field::new("id", DataType::Int64, false),
Field::new("age", DataType::Int64, false),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if adding the unparsing test here is appropriate. 🤔 Typically, we add unparse-related tests in datafusion/sql/tests/cases/plan_to_sql.rs

I left a disabled test for this issue in the previous PR #12158. I guess we can just enable it and remove this test.

// TODO: support filters for table scan with alias. Enable this test after #12368 issue is fixed

Comment on lines 601 to 605
.reduce(|acc, expr_result| match (acc, expr_result) {
(Ok(acc_expr), Ok(expr)) => Ok(acc_expr.and(expr)),
(Err(e), _) | (_, Err(e)) => Err(e),
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify here like this

Suggested change
.reduce(|acc, expr_result| match (acc, expr_result) {
(Ok(acc_expr), Ok(expr)) => Ok(acc_expr.and(expr)),
(Err(e), _) | (_, Err(e)) => Err(e),
})
.reduce(|acc, expr_result| {
acc.and_then(|acc_expr| {
expr_result.map(|expr| acc_expr.and(expr))
})
})

datafusion/sql/src/unparser/rewrite.rs Show resolved Hide resolved
@alamb
Copy link
Contributor

alamb commented Sep 13, 2024

I think @goldmedal 's comments are all great. Once those have been addressed this PR will be ready to go from my persective.

Thank you @Lordworms @goldmedal and @dmitrybugakov

@alamb alamb changed the title adding alias for table scan filter adding alias for table scan filter in sql unparser Sep 13, 2024
@github-actions github-actions bot removed the core Core DataFusion crate label Sep 15, 2024
@Lordworms
Copy link
Contributor Author

@goldmedal @alamb @dmitrybugakov Thanks for the review!

@alamb alamb changed the title adding alias for table scan filter in sql unparser feat(unparser): adding alias for table scan filter in sql unparser Sep 15, 2024
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.

Thanks -- looks good to me

@alamb alamb merged commit aac10a4 into apache:main Sep 15, 2024
25 checks passed
This pull request was closed.
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.

Unparsing TableScan with an alias and a pushdown filter to SQL string
4 participants