Skip to content
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

feat(sqlparser): support literal integers in hex / oct / bin #14262

Merged
merged 3 commits into from Dec 29, 2023

Conversation

xiangjinwu
Copy link
Contributor

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Resolves #14096. The new syntax was added in PostgreSQL 16 for SQL 202x.

Limitations:

  • Underscores as separators are not supported (eg 0xdead_beef)
  • Only during sqlparsing but not execution (eg '0x20'::int / source ingestion / pgwire text protocol)

Breaking change:

  • For 0b10, older version interprets it as 0 as b10 but new versions interprets it as binary 10 (= 2 in decimal). It was not an issue in PostgreSQL because such input has always been considered invalid and we are now rejecting 0c10 similarly.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

Integer literals can now be given in hex 0x, oct 0o and bin 0b.

Comment on lines -542 to -549
if s.chars().all(|x| x.is_ascii_digit() || x == '.') {
let mut s = peeking_take_while(&mut s.chars().peekable(), |ch| {
ch.is_ascii_digit() || ch == '.'
});
let s2 = peeking_take_while(chars, |ch| ch.is_ascii_digit() || ch == '.');
s += s2.as_str();
return Ok(Some(Token::Number(s)));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This hack was here because HiveQL identifier can start with 0..=9
https://github.com/sqlparser-rs/sqlparser-rs/pull/235/files

@xiangjinwu xiangjinwu added this pull request to the merge queue Dec 29, 2023
Merged via the queue into main with commit 08362b7 Dec 29, 2023
28 of 29 checks passed
@xiangjinwu xiangjinwu deleted the feat-sqlparser-literal-hex branch December 29, 2023 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support hexadecimal / non-decimal numeric constants
2 participants