-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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.
Thanks @Lordworms working on this. Overall looks good to me. Just leave some suggestions.
fn test_alias_pushdown() -> Result<()> { | ||
let schema = Schema::new(vec![ | ||
Field::new("id", DataType::Int64, false), | ||
Field::new("age", DataType::Int64, false), | ||
]); |
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 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 |
datafusion/sql/src/unparser/plan.rs
Outdated
.reduce(|acc, expr_result| match (acc, expr_result) { | ||
(Ok(acc_expr), Ok(expr)) => Ok(acc_expr.and(expr)), | ||
(Err(e), _) | (_, Err(e)) => Err(e), | ||
}) |
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.
We can simplify here like this
.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)) | |
}) | |
}) |
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 |
3a63ca0
to
d744393
Compare
@goldmedal @alamb @dmitrybugakov Thanks for the review! |
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.
Thanks -- looks good to me
* init (apache#12453) * Fix unparse table scan with the projection pushdown (apache#12534) * unparse the projection base on the source schema * refactor and enhance the test * Fix unparsing OFFSET (apache#12539) * Unparse Sort with pushdown limit to SQL string (apache#12873) * unparse Sort with push down limit * cargo fmt * set query limit directly * Unparse `SubqueryAlias` without projections to SQL (apache#12896) * change pub function comment to doc * unparse subquery alias without projections * fix tests * rollback the empty line * rollback the empty line * exclude the table_scan with pushdown case * fmt and clippy * simplify the ast to string and remove unused debug code * enhance unparsing plan with pushdown to avoid unnamed subquery (apache#13006) * Update --------- Co-authored-by: Lordworms <[email protected]> Co-authored-by: Jax Liu <[email protected]> Co-authored-by: Justus Flerlage <[email protected]>
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?