Skip to content

Refine join parsing #111

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

Merged
merged 3 commits into from
Jun 14, 2019
Merged

Refine join parsing #111

merged 3 commits into from
Jun 14, 2019

Conversation

benesch
Copy link
Contributor

@benesch benesch commented Jun 10, 2019

Additional join tweaks for better compliance with the standard. Extracted from #109.

@nickolay no rush at all on this! I'm not currently in need of the changes here, but I wanted to cross the i's and dot the t's while the code was fresh in my mind.

@benesch benesch requested a review from nickolay June 10, 2019 15:21
@coveralls
Copy link

coveralls commented Jun 10, 2019

Pull Request Test Coverage Report for Build 348

  • 57 of 63 (90.48%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 91.906%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tests/sqlparser_common.rs 27 33 81.82%
Totals Coverage Status
Change from base Build 342: 0.003%
Covered Lines: 4292
Relevant Lines: 4670

💛 - Coveralls

Copy link
Contributor

@nickolay nickolay left a comment

Choose a reason for hiding this comment

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

Hey @benesch, thanks for extracting this into its own PR!

As promised, after thinking about it I agree with your approach -- while it seems this could be theoretically parsed without backtracking, it would significantly complicate the code in exchange for being more efficient when parsing nested joins, which I expect to be quite rare.

I had some suggestions, which I pushed as separate commits here, to be squashed with existing ones, if you agree with the changes.

@benesch
Copy link
Contributor Author

benesch commented Jun 14, 2019

Yeah, the new commits look great! I'll squash and merge in just a moment.

benesch and others added 3 commits June 14, 2019 16:28
This commit adds support for derived tables (i.e., subqueries) that
incorporate set operations, like:

    SELECT * FROM (((SELECT 1) UNION (SELECT 2)) t1 AS NATURAL JOIN t2)

This introduces a bit of complexity around determining whether a left
paren starts a subquery, starts a nested join, or belongs to an
already-started subquery. The details are explained in a comment within
the patch.
The SQL specification prohibits constructions like

    SELECT * FROM a NATURAL JOIN (b)

where b sits alone inside parentheses. Parentheses in a FROM entry
always introduce either a derived table or a join.
@benesch benesch merged commit 98a06d6 into apache:master Jun 14, 2019
@benesch benesch deleted the join-tweaks branch June 21, 2019 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants