-
Notifications
You must be signed in to change notification settings - Fork 711
Postgres: enhance NUMERIC/DECIMAL parsing to support negative scale #1990
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
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c949e9
Postgres: enhance NUMERIC/DECIMAL parsing to support negative scale v…
IndexSeek a6ae8a3
docs: reduce parse_signed integer commenting
IndexSeek da3c384
docs: remove dialect callout
IndexSeek 19d163d
feat: simplify parse_signed_integer implementation
IndexSeek d31b302
test: merge negative scale tests
IndexSeek 427988e
feat: implement improved parsing for signed integers
IndexSeek 1c9ad37
feat: enhance signed integer parsing to handle explicit '+' sign
IndexSeek 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.
was the pattern in the previous comment example insufficient? I think the current approach to optionally multiply by negative makes things slightly longer to follow what the code is trying to achieve.
fyi note ideally we use
next_token_refsince that avoid cloning, especially given thatparse::<i64>does not require an owned valueUh oh!
There was an error while loading. Please reload this page.
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.
When I tried to implement your suggested pattern, it failed on test cases with explicit
+signs (likeNUMERIC(10,+5)) becauseparse_literal_uint()expected a number token. I should have posted my issue earlier.I actually went back and tested that PostgreSQL doesn't even take that (ERROR: type modifiers must be simple constants or identifiers), so I was overcomplicating it and I will remove this test case.
I did not find
next_token_refbut it looks thatadvance_token()+get_current_token()will give us this behavior (#1618)?Here's what I am working with right now after removing that explicit "+" test:
I believe this should only clone the string data and not the tokens now.
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.
Ah yeah that makes sense, I confused
peek_token_refand was hoping to avoid the clone entirely but looking atSelf::parsenow I see its not currently set up to take in references so the current approach to clone the string sounds reasonable! Here's a couple minor updates to your example I think should do what we intended?Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for the suggestion! It does read cleaner not starting with negation, looking back, opening with
if !self.consume_token(&Token::Minus)felt a bit strange.I like how your solution still handles the + sign, but I noticed a few issues with the logic flow. I think that with an optional + token on
let _ = self.consume_token(&Token::Plus);followed byself.advance_token()and thenself.get_current_token()could advance twice and potentially skip the actual number token.I did take a look at
peek_token_refand was wondering if we could use it like so?I think that should avoid us needing to consume the token until we know we have a number.
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.
Should we still parse the "+" character or error out? I know I originally added a test for it but I'm not sure any dialects support a "+" token in the scale definition for numeric types.
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 the last snippet sounds reasonable to me! I think we should still parse the
+character since the idea is that the api can be used in other contexts beyond the numeric type scaleUh oh!
There was an error while loading. Please reload this page.
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.
That sounds good to me! I also added back that test that was explicitly checking to ensure that "+" would work and be removed when converted back to a string, but we can remove those lines if it is redundant.