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

Improvements to numeric literals (underscores, hex, octal, binary) #17776

Merged
merged 2 commits into from
Jun 8, 2023

Conversation

martint
Copy link
Member

@martint martint commented Jun 6, 2023

As specified in SQL 2023:

<unsigned integer> ::=
    <unsigned decimal integer>
  | <unsigned hexadecimal integer>
  | <unsigned octal integer>
  | <unsigned binary integer>

<unsigned decimal integer> ::=
  <digit> [ { [ <underscore> ] <digit> }... ]

<unsigned hexadecimal integer> ::=
  0X { [ <underscore> ] <hexit> }...

<unsigned octal integer> ::=
  0O { [ <underscore> ] <octal digit> }...

<unsigned binary integer> ::=
  0B { [ <underscore> ] <binary digit> }...

Release notes

(x) Release notes are required, with the following suggested text:

# General
* Add support for underscores in numeric literals.
* Add support for hexadecimal, binary, and octal numeric literals.

@cla-bot cla-bot bot added the cla-signed label Jun 6, 2023
@martint martint force-pushed the literals-underscore branch 3 times, most recently from f11da1a to 09145d6 Compare June 8, 2023 01:54
@martint martint changed the title Add support for underscores in numeric literals Improvements to numeric literals (underscores, hex, octal, binary) Jun 8, 2023
value = value.replace("_", "");

if (value.startsWith("0x") || value.startsWith("0X")) {
return Long.parseLong(value.substring(2), 16);
Copy link
Member

Choose a reason for hiding this comment

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

BTW, in general this syntax is dangerous because parse long supports a leading sign. It isn't a problem here because the grammar doesn't allow that, but I ran into code in Hive that did this and ended up supporting 0x-123

@martint martint force-pushed the literals-underscore branch from 09145d6 to c2df597 Compare June 8, 2023 04:24
martint added 2 commits June 7, 2023 21:32
As specified in SQL 2023:

    <unsigned decimal integer> ::=
      <digit> [ { [ <underscore> ] <digit> }... ]
@martint martint force-pushed the literals-underscore branch from c2df597 to 7cba489 Compare June 8, 2023 04:32
@martint martint merged commit 025ea1c into trinodb:master Jun 8, 2023
@martint martint deleted the literals-underscore branch June 8, 2023 15:35
@github-actions github-actions bot added this to the 420 milestone Jun 8, 2023
@mosabua
Copy link
Member

mosabua commented Jun 8, 2023

@nineinchnick and @mosabua are working on docs for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants