tconbeer / sqlfmt

sqlfmt formats your dbt SQL files so you don't have to
https://sqlfmt.com
Apache License 2.0
390 stars 16 forks source link

Formatting of ClickHouse aggregate function `any` results in extra whitespace and poor formatting #483

Closed damirbk closed 11 months ago

damirbk commented 11 months ago

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 commented 11 months ago

Thanks for the report!

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

tconbeer commented 11 months ago

Similar to #478

damirbk commented 11 months ago

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 commented 11 months ago

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