Skip to content

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

@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
sgrebnov pushed a commit to spiceai/datafusion that referenced this pull request Oct 23, 2024
sgrebnov added a commit to spiceai/datafusion that referenced this pull request Oct 24, 2024
* 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 <48054792+Lordworms@users.noreply.github.com>
Co-authored-by: Jax Liu <liugs963@gmail.com>
Co-authored-by: Justus Flerlage <justus@sutsuj.com>
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