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

[FORMATTING] Formatter Adds Unwanted Space Before Dash and Number in Project Names (e.g., project -12345) #791

Open
motherway opened this issue Oct 22, 2024 · 3 comments

Comments

@motherway
Copy link

motherway commented Oct 22, 2024

Screenshot 2024-10-22 at 9 20 17 AM

Whenever a project name contains a dash followed by a number then it is being interpreted as a minus number value and being separated when formatted. This is troublesome for us as a lot of our project names contain this format and the formatter is breaking our queries as a result.

We can't always rely on escaping the project name as these queries are written by end users in the browser.

Input data

-- BigQuery
select * from project-12345.table.column

Expected Output

select
  *
from
  project-12345.table.column

Actual Output

select 
  *
from
  project -12345.table.column

Usage

  • What SQL language(s) does this apply to?
    BigQuery
  • Which SQL Formatter version are you using?
    15.4.5
@motherway motherway added the bug label Oct 22, 2024
@nene
Copy link
Collaborator

nene commented Oct 22, 2024

Thanks for reporting.

Unfortunately this is a problem that's pretty much impossible to fix with the current architecture of SQL Formatter. This is because foo-bar.baz.zap would have to be treated differently based on the context:

  • when inside a FROM-clause it needs to be parsed as project-name.table.column.
  • when inside some expression it needs to be parsed as identifier - identifer.field.field.

SQL Formatter doesn't properly parse the SQL, so it can't really tell when it should treat it in one or the other way. I guess one option would be to always parse such constructs as project-name, as this way the formatter would avoid introducing syntax errors.

Anyway... Because of problems like that I created another SQL formatting tool prettier-plugin-sql-cst which does have a pretty solid BigQuery support and it does not suffer from issues like this. I suggest you give it a try.

@nene
Copy link
Collaborator

nene commented Oct 22, 2024

PS. Just FYI, when reporting bugs to this or any other open-source project, please don't answer "latest" when asked which version number you're using. That "latest" will no more be the latest version when somebody looks at this bug report a year from now. Or I might have released a new version just minutes ago, and would not have any idea whether your definition of "latest" refers to that version or some earlier one.

@motherway
Copy link
Author

PS. Just FYI, when reporting bugs to this or any other open-source project, please don't answer "latest" when asked which version number you're using. That "latest" will no more be the latest version when somebody looks at this bug report a year from now. Or I might have released a new version just minutes ago, and would not have any idea whether your definition of "latest" refers to that version or some earlier one.

That makes total sense. Apologies I wrote it in a hurry.

@nene nene added the bigquery label Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants