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 issue with table names #128

Open
kollerdaniel opened this issue Jan 6, 2023 · 2 comments
Open

Formatting issue with table names #128

kollerdaniel opened this issue Jan 6, 2023 · 2 comments

Comments

@kollerdaniel
Copy link

kollerdaniel commented Jan 6, 2023

Hi,

I use ZetaSQL for syntax checking, formatting checking and file formatting.
While using the tool I ran into an issue that if I use table names like this:

table-name-example

this will be the result of the formatting:

table - name - example

My formatter configuration file looks like this:

allowInvalidTokens: false
capitalizeKeywords: false
enforceSingleQuotes: false
indentationSpaces: 4
expandFormatRanges: false
lineLengthLimit: 100
preserveLineBreaks: false

I read the documentation about the Lexical structure and syntax and it says that I can use unquoted identifiers with single dashes. Therefore I do not understand the reason for the issue.
Is there a solution to the issue, or a configuration that can be set to avoid this?

@a-litvinov
Copy link

Hi Daniel,

Thanks for reporting the issue! Unfortunately, it is a known limitation of the formatter.
The problem is that formatter doesn't use the ZetaSQL parser to understand the meaning of each token - it relies on a very simplified heuristics set, that is quite lenient and allows formatting something that wouldn't even parse (which is quite common situation in SQL world, think, e.g., about macros). Basically, formatter needs to know all locations in grammar where table name is expected to make a distinction between a dashed identifier and a math expression.

The only workaround for now is to escape the table names that contain dashes with backticks `, even though, ZetaSQL standard allows using the names unescaped.

@kollerdaniel
Copy link
Author

@a-litvinov thanks for your reply!

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

No branches or pull requests

2 participants