Skip to content

Assorted code simplification and doc improvements #131

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 8 commits into from
Jul 10, 2019

Conversation

nickolay
Copy link
Contributor

@nickolay nickolay commented Jul 9, 2019

Including some follow-ups to #124 and #50 and parse_comma_separated (03efcf6)

nickolay added 8 commits July 9, 2019 01:38
To use the new helper effectively, a few related changes were required:

- Each of the parse_..._list functions (`parse_cte_list`,
  `parse_order_by_expr_list`, `parse_select_list`) was replaced with a
  version that parses a single element of the list (e.g. `parse_cte`),
  with their callers now using
  `self.parse_comma_separated(Parser::parse_<one_element>)?`

- `parse_with_options` now parses the WITH keyword and a separate
  `parse_sql_option` function (named after the struct it produces) was
  added to parse a single k=v option.

- `parse_list_of_ids` is gone, with the '.'-separated parsing moved to
  `parse_object_name`.


Custom comma-separated parsing is still used in:
- parse_transaction_modes (where the comma separator is optional)
- parse_columns (allows optional trailing comma, before the closing ')')
It used to consume the `RParen` closing the encompassing `OVER (`, even
when no window frame was parsed, which confused me a bit, even though
I wrote it initially.

After fixing that, I took the opportunity to reduce nesting and
duplication a bit.
The note about WindowFrameBound::Following being only valid "in
WindowFrame::end_bound" was both

- confusing, as it was based on the ANSI SQL syntax the parser doesn't
  adhere to -- though it sounded like a promise about the AST one could
  expect to get from the parser
- and incomplete, as the reality is that the bounds validation the SQL
  engine might want to perform is more complex. For example Postgres
  documentation says <https://www.postgresql.org/docs/11/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS>:

> Restrictions are that frame_start cannot be UNBOUNDED FOLLOWING,
> frame_end cannot be UNBOUNDED PRECEDING, and the frame_end choice
> cannot appear earlier in the above list of frame_start and frame_end
> options than the frame_start choice does — for example RANGE BETWEEN
> CURRENT ROW AND offset PRECEDING is not allowed. But, for example,
> ROWS BETWEEN 7 PRECEDING AND 8 PRECEDING is allowed, even though it
> would never select any rows.
@nickolay nickolay requested a review from benesch July 9, 2019 00:37
@coveralls
Copy link

coveralls commented Jul 9, 2019

Pull Request Test Coverage Report for Build 413

  • 147 of 158 (93.04%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 92.444%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser.rs 98 100 98.0%
src/ast/operator.rs 17 20 85.0%
src/ast/mod.rs 21 27 77.78%
Totals Coverage Status
Change from base Build 412: -0.1%
Covered Lines: 4282
Relevant Lines: 4632

💛 - Coveralls

Copy link
Contributor

@benesch benesch left a comment

Choose a reason for hiding this comment

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

LGTM!

@nickolay nickolay merged commit 391a54b into apache:master Jul 10, 2019
@nickolay nickolay deleted the pr/refactoring branch July 10, 2019 23:19
@nickolay
Copy link
Contributor Author

Thanks for the review!

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