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

Bug when formatting float literals in BigQuery #321

Closed
liaopeiyuan opened this issue Nov 17, 2022 · 2 comments · Fixed by #325
Closed

Bug when formatting float literals in BigQuery #321

liaopeiyuan opened this issue Nov 17, 2022 · 2 comments · Fixed by #325
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@liaopeiyuan
Copy link

Describe the bug
sqlfmt adds unnecessary spaces for float literals in E notation in BigQuery

To Reproduce
1e-9

Expected behavior
1e-9

Actual behavior
1 e -9

Additional context
We are using the sqlfmt embedded in dbt develop. The UI on https://sqlfmt.com/ produces the same result.

@tconbeer tconbeer added the bug Something isn't working label Nov 17, 2022
@tconbeer tconbeer added this to the v0.14.0 milestone Nov 17, 2022
@tconbeer tconbeer added the good first issue Good for newcomers label Nov 17, 2022
@tconbeer
Copy link
Owner

tconbeer commented Nov 17, 2022

Thanks for the report, @liaopeiyuan . I knew, and then forgot, that number literals could use scientific notation. This is true in postgres too. This is definitely a bug; I'll get this fixed asap.

We just need to change the number Rule to add a pattern that will match something like 1e-9 or -55.55e10. Decimals after the e are not supported (at least on pg).

Rule(
name="number",
priority=350,
pattern=group(
r"-?\d+\.?\d*",
r"-?\.\d+",
),

Snowflake docs include a pseudo-regex, which is really helpful: https://docs.snowflake.com/en/sql-reference/data-types-numeric.html#numeric-constants

tconbeer added a commit that referenced this issue Nov 21, 2022
* feat: improve numeric constant handling, close #321

* chore: update primer refs
@tconbeer
Copy link
Owner

@liaopeiyuan This patch has been merged to main. Thanks again for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants