Skip to content

Refactor parse_joins #87

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 3, 2019
Merged

Refactor parse_joins #87

merged 3 commits into from
Jun 3, 2019

Conversation

nickolay
Copy link
Contributor

@nickolay nickolay commented Jun 2, 2019

While preparing to add support for the non-standard CROSS/OUTER APPLY (an alternative syntax for LATERAL invented by MS and adopted by Oracle) I've tweaked the internals of parse_joins to reduce code duplication, added tests for NATURAL and fixed a couple minor issues (extra whitespace in the serializer and NATURAL being silently eaten when not followed by a JOIN).

(This does not change the AST, and doesn't deal with #83.)

nickolay added 3 commits June 3, 2019 02:44
- use `if !self.consume_token(&Token::Comma) { break; }` to consume the
  comma and exit the loop if no comma found.
- coalesce two `{ false }` blocks in `consume_token` by using a match guard
This block parses one of:
- `[ INNER ] JOIN <table_factor> <join_constraint>`
- `{ LEFT | RIGHT | FULL } [ OUTER ] JOIN <table_factor> <join_constraint>`

..but it was hard to see because of the duplication.
- reduce duplication in the handling of implicit/cross joins and make
  the flow of data slightly clearer by returning the `join` instead of
  pushing it and exiting early.

  (I wanted the block that currently returns `join` to return one of
  JoinOperator::* tags, so that `parse_table_factor` and the construction
  of the `Join` struct could happen after we've parsed the JOIN keywords,
  but that seems impossible.)

- move the check for the NATURAL keyword into the block that deals with 
  INNER/OUTER joins that support constraints (and thus can be preceded
  by "NATURAL")

- add a check for NATURAL not followed by a known join type with a test

- add more tests for NATURAL joins (we didn't have any), and fix
  whitespace bug in `to_string()` that was uncovered (we emitted an
  extra space: `foo NATURAL JOIN bar `)
@nickolay nickolay requested a review from benesch June 2, 2019 23:59
@coveralls
Copy link

Pull Request Test Coverage Report for Build 235

  • 62 of 66 (93.94%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage remained the same at 90.259%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/sqlparser.rs 34 35 97.14%
tests/sqlparser_common.rs 26 29 89.66%
Files with Coverage Reduction New Missed Lines %
src/sqlparser.rs 1 90.33%
Totals Coverage Status
Change from base Build 234: 0.0%
Covered Lines: 3345
Relevant Lines: 3706

💛 - Coveralls

@benesch
Copy link
Contributor

benesch commented Jun 3, 2019

Heh, I've got a patch somewhere in my stack that addresses that same whitespace bug. Everything LGTM!

@benesch
Copy link
Contributor

benesch commented Jun 3, 2019

I'm going to merge this now, actually, because I've got a patch for #83 coming up that's going to need a rebase.

@benesch benesch merged commit 85ba953 into apache:master Jun 3, 2019
@nickolay nickolay deleted the pr/join-refactor branch June 18, 2019 23:48
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