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

Allow subqueries without aliases #2418

Merged
merged 2 commits into from
May 2, 2022

Conversation

andygrove
Copy link
Member

Which issue does this PR close?

Closes #2417

Rationale for this change

I am trying to run some ANSI SQL that works fine in Apache Spark but fails in DataFusion because we currently require subqueries to have aliases.

As described in the issue though, Postgres does require subqueries to be aliased, so that is probably what determined the current behavior?

Should we make this behavior configurable?

There was a discussion about this in #1067

What changes are included in this PR?

Remove the check that caused subqueries without aliases to fail. Note that there were no tests for this functionality.

Are there any user-facing changes?

No

@github-actions github-actions bot added the datafusion Changes in the datafusion crate label May 2, 2022
@andygrove
Copy link
Member Author

@alamb @yjshen @xudong963 @houqp How do you think we should handle this? Should I consider enabling this or not based on the SQL dialect being used?

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.

I don't honestly know the deeper background and understanding of why postgres requires an alias or if there are deeper implications to allowing unaliased subqueries.

However, I think the additional test coverage is 👍 And the fact there are no additional errors is a good sign to me.

assert_batches_eq!(expected, &actual);
Ok(())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could also add a test here that had two unaliased subqueries (should result in a cross join) as a potential other case that would be good to cover

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review @alamb. I added the suggested test and did not run into problems so will go ahead and merge this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome!

@andygrove andygrove merged commit cb2cbbe into apache:master May 2, 2022
@andygrove andygrove deleted the remove-subquery-alias-check branch May 2, 2022 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow subqueries without aliases
2 participants