Skip to content

Conversation

WittierDinosaur
Copy link
Contributor

@WittierDinosaur WittierDinosaur commented Apr 22, 2025

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 in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

Copy link
Contributor

github-actions bot commented Apr 22, 2025

Coverage Results ✅

Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL   19634      0   100%

249 files skipped due to complete coverage.

Copy link
Member

@alanmcruickshank alanmcruickshank left a 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.

Comment on lines 217 to 233
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,
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@alanmcruickshank alanmcruickshank left a comment

Choose a reason for hiding this comment

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

Much cleaner 💯

@alanmcruickshank alanmcruickshank added this pull request to the merge queue Apr 29, 2025
Merged via the queue into main with commit a670227 Apr 29, 2025
30 checks passed
@alanmcruickshank alanmcruickshank deleted the optionally-delimited branch April 29, 2025 12:40
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.

Snowflake ALTER USER SET option does not works with spaces
2 participants