-
-
Notifications
You must be signed in to change notification settings - Fork 873
OptionallyDelimited Grammar #6837
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
Conversation
Coverage Results ✅
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need a different approach here, this way will fail if there's ever a mix of spaces and commas. I'm happy to take a crack at the alternative method if you're not sure.
super().__init__( | ||
*args, | ||
Delimited( | ||
*args, | ||
delimiter=delimiter, | ||
allow_trailing=allow_trailing, | ||
terminators=terminators, | ||
reset_terminators=reset_terminators, | ||
min_delimiters=min_delimiters, | ||
bracket_pairs_set=bracket_pairs_set, | ||
allow_gaps=allow_gaps, | ||
optional=optional, | ||
), | ||
terminators=terminators, | ||
reset_terminators=reset_terminators, | ||
allow_gaps=allow_gaps, | ||
optional=optional, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it this way means that we can now parse:
ALTER USER "John" SET DEFAULT_ROLE = JOHNNY DEFAULT_WAREHOUSE = FEU COMMENT = "Foo";
ALTER USER "John" SET DEFAULT_ROLE = JOHNNY, DEFAULT_WAREHOUSE = FEU, COMMENT = "Foo";
But if there's a mix of commas and space delimiters, then it will fail 🤔 . e.g.
ALTER USER "John" SET DEFAULT_ROLE = JOHNNY DEFAULT_WAREHOUSE = FEU, COMMENT = "Foo";
I realise it's an edge case in an edge case, but I wonder if we need a different approach. In the Delimited
grammar, the section of code which looks for delimiters or content is fairly compact, and it probably wouldn't be crazy to extent that to search optionally for both if configured that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a fair point. I suppose we just need to change the matching algorithm in Delimited() to depend on a variable to set in OptionallyDelimited(). I think that shouldn't be all that hard actually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner 💯
Brief summary of the change made
Create OptionallyDelimited grammar, and implement its first use case.
Fixes #6824
Are there any other side effects of this change that we should be aware of?
No
Pull Request checklist
Please confirm you have completed any of the necessary steps below.
Included test cases to demonstrate any code changes, which may be one or more of the following:
.yml
rule test cases intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withtox -e generate-fixture-yml
).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.