Skip to content

Fix parsing of COLLATE after parentheses in expressions #507

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 1 commit into from
May 25, 2022

Conversation

ghost
Copy link

@ghost ghost commented May 24, 2022

Version 0.17.0 fails to parse COLLATE after an expression that's surrounded by parentheses, like (name) COLLATE "de_DE". This regression was introduced by da6a17b (#466), where an "early return" is used to return the parsed expression when the closing parenthesis isn't followed by a period, https://github.com/sqlparser-rs/sqlparser-rs/blob/4070f3ec6e616be6e9249f7202338e0f05969237/src/parser.rs#L521-L524 but this return causes the code which parses COLLATE https://github.com/sqlparser-rs/sqlparser-rs/blob/4070f3ec6e616be6e9249f7202338e0f05969237/src/parser.rs#L542-L549 to be skipped.

Replacing the early return with if-else fixes this regression, as verified by a test that I've added.

@@ -561,6 +561,15 @@ fn parse_collate() {
);
}

#[test]
fn parse_collate_after_parens() {
let sql = "SELECT (name) COLLATE \"de_DE\" FROM customer";
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

alamb=# select (name) COLLATE "de_DE" from foo;
 name 
------
 a
 b
 c
 d
(4 rows)

@coveralls
Copy link

Pull Request Test Coverage Report for Build 2378293006

  • 11 of 12 (91.67%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.004%) to 89.826%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser.rs 7 8 87.5%
Files with Coverage Reduction New Missed Lines %
src/parser.rs 1 83.0%
Totals Coverage Status
Change from base Build 2378120823: 0.004%
Covered Lines: 8326
Relevant Lines: 9269

💛 - Coveralls

@alamb alamb merged commit 0fa812b into apache:main May 25, 2022
@ghost ghost deleted the collate-regression branch May 26, 2022 07:32
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.

2 participants