-
Notifications
You must be signed in to change notification settings - Fork 602
Fix tokenization of qualified identifiers with numeric prefix. #1803
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
iffyio
merged 5 commits into
apache:main
from
romanb:qualified-identifier-numeric-prefix
Apr 11, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0279883
Fix tokenization of qualified identifiers with numeric prefix.
0eda729
Update inline comment.
e32c3c8
Improve tests as suggested in code review.
aab48d4
Alternative fix implementated in the parser.
a47e2ab
Revert "Alternative fix implementated in the parser."
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we implement instead in the parser as a special for
self.dialect.supports_numeric_prefix()
? somewhat similar to what we do for BigQuery here. In that when its time to combine identifiers into a compound identifier we check if each subsequent identifier part is unquoted and prefixed by.
, and if so we drop the prefix. I imagine that would be done hereThinking that could be a smaller change since the behavior needs a bit of extra context around the tokens which the tokenizer isn't so good at handling cleanly
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.
Thank you for the review and the suggestion. The latest commit implements an alternative approach within
Parser#parse_compound_expr
. However, I have to admit that I personally prefer the previous fix in the tokenizer, for a few reasons:The
Tokenizer
is part of the public API of the crate, and without fixing this in the tokenizer, it will continue to exhibit the following behavior with the Mysql dialect:t.1to2
tokenizes tot
(Word),.1to2
(Word)t.1e2
tokenizes tot
(Word),.1e2
(Number)t.`1to2`
tokenizes tot
(Word),.
(Period),1to2
(Word)t.`1e2`
tokenizes tot
(Word),.
(Period)1e2
(Word)This could be very surprising for users and arguably be considered incorrect (when using the Mysql dialect).
The handling of
Word
andNumber
tokens inparse_compound_expr
is not the most elegant with having to split off the.
and having to create the correct off-by-one spans accordingly.Unqualified identifiers that start with digits are already handled in the tokenizer - and I think have to be (see Support identifiers beginning with digits in MySQL #856). Handling the same problem of misinterpreted tokens for qualified identifiers in the parser seems a bit disconnected and a like a downstream solution to the tokenizer producing incorrect tokens, at least that is how I currently perceive it (see point 1).
Let me know which solution you prefer (with or without the latest commit) or if you have another idea.
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 think that's fair, we can revert back to the tokenizer version in that case? to keep the tokenizer behavior non-surprising
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.
Done!