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 of ClickHouse aggregate function any results in extra whitespace and poor formatting #483

Closed
damirbk opened this issue Sep 15, 2023 · 4 comments · Fixed by #486
Labels
bug Something isn't working
Milestone

Comments

@damirbk
Copy link

damirbk commented Sep 15, 2023

Describe the bug
sqlfmt doesn't seem to understand that the any function is an aggregate function and not the typical SQL ANY operator. See examples below.

To Reproduce
File example1.sql:

select any(number) as any_number from (select number from system.numbers limit 10)

Also, file example2.sql:

select max(number) as max_number, min(number) as min_number, any(number) as any_number, avg(number) as avg_number from (select number from system.numbers limit 10)

Expected behavior
For example1.sql:

select any(number) as any_number from (select number from system.numbers limit 10)

(no change)

For example2.sql:

select
    max(number) as max_number,
    min(number) as min_number,
    any(number) as any_number,
    avg(number) as avg_number
from (select number from system.numbers limit 10)

Actual behavior
After running sqlfmt example1.sql --dialect clickhouse --line-length 88:

select any (number) as any_number from (select number from system.numbers limit 10)

Extra whitespace is added incorrectly.

After running sqlfmt example2.sql --dialect clickhouse --line-length 88:

select
    max(number) as max_number,
    min(number) as min_number, any (number) as any_number,
    avg(number) as avg_number
from (select number from system.numbers limit 10)

Additional context
What is the output of sqlfmt --version?

sqlfmt, version 0.19.2

@tconbeer
Copy link
Owner

Thanks for the report!

Does the formatted code execute on clickhouse or does it complain about the space?

@tconbeer
Copy link
Owner

Similar to #478

@damirbk
Copy link
Author

damirbk commented Sep 15, 2023

Thanks for all the work you do! It actually works fine in ClickHouse with the spaces; it's just the formatting that becomes strange.

@tconbeer
Copy link
Owner

tconbeer commented Sep 15, 2023

Cool, thanks, snowflake is the same way.

Any() and all() are also in postgres now so we'll just make this fix to the polyglot dialect

@tconbeer tconbeer added the bug Something isn't working label Sep 15, 2023
@tconbeer tconbeer added this to the v 0.20.0 milestone Sep 15, 2023
tconbeer added a commit that referenced this issue Sep 25, 2023
tconbeer added a commit that referenced this issue Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants