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

Enhance table scan unparsing to avoid unnamed subqueries. #13006

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

goldmedal
Copy link
Contributor

@goldmedal goldmedal commented Oct 18, 2024

Which issue does this PR close?

It's a follow-up PR of #12896

Rationale for this change

from #12896 (comment)

What changes are included in this PR?

Are these changes tested?

Enhance the original tests

Are there any user-facing changes?

@github-actions github-actions bot added the sql SQL Planner label Oct 18, 2024
@goldmedal goldmedal changed the title Enhance unpasring the table scan with pushdown operations to avoid unnamed subquery Enhance table scan unparsing to avoid unnamed subqueries. Oct 18, 2024
@goldmedal goldmedal marked this pull request as ready for review October 18, 2024 14:44
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.

This makes sense to me -- thank you @goldmedal

Perhaps @phillipleblanc and @sgrebnov have some time to review this as well

@alamb
Copy link
Contributor

alamb commented Oct 21, 2024

Let's merge this in and we can address any feedback as a follow on PR

@alamb alamb merged commit 2535d88 into apache:main Oct 21, 2024
26 checks passed
Comment on lines +637 to +642
if alias.is_some()
&& (table_scan.projection.is_some() || !table_scan.filters.is_empty())
{
builder = builder.alias(alias.clone().unwrap())?;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if alias.is_some()
&& (table_scan.projection.is_some() || !table_scan.filters.is_empty())
{
builder = builder.alias(alias.clone().unwrap())?;
}
if let Some(ref alias) = alias {
if table_scan.projection.is_some() || !table_scan.filters.is_empty() {
builder = builder.alias(alias.clone())?;
}
}

I find this to be slightly cleaner

Comment on lines +693 to +697
if alias.is_some()
&& (table_scan.projection.is_none() && table_scan.filters.is_empty())
{
builder = builder.alias(alias.clone().unwrap())?;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if alias.is_some()
&& (table_scan.projection.is_none() && table_scan.filters.is_empty())
{
builder = builder.alias(alias.clone().unwrap())?;
}
if let Some(alias) = alias {
if table_scan.projection.is_some() || !table_scan.filters.is_empty() {
builder = builder.alias(alias)?;
}
}

No need for a clone here.

@phillipleblanc
Copy link
Contributor

Whoops, I had pending feedback that I didn't submit in time.

@alamb
Copy link
Contributor

alamb commented Oct 22, 2024

Whoops, I had pending feedback that I didn't submit in time.

I do that far more often than I would like to admit. Maybe it is a good excuse for a follow on PR

@goldmedal goldmedal deleted the feature/enahce-pushdown-unparsing branch October 22, 2024 14:22
@goldmedal
Copy link
Contributor Author

Whoops, I had pending feedback that I didn't submit in time.

@phillipleblanc I just noticed your reply now 😮. These suggestions make sense to me. I'll submit a follow PR for them soon.
Thanks!

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 <[email protected]>
Co-authored-by: Jax Liu <[email protected]>
Co-authored-by: Justus Flerlage <[email protected]>
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.

3 participants