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

Strange formatting for Athena SQL array/map types #500

Closed benjamin-awd closed 10 months ago

benjamin-awd commented 10 months ago

Describe the bug Athena has array and map datatypes, that use < and > characters. Running sqlfmt on queries that use these types produce unexpected behaviour.

Expected behavior

select cast(json_parse(foo) as array<map<varchar,varchar>>) from dwh.table

Actual behavior Strange spacing in between < and > separators

select cast(json_parse(foo) as array<map < varchar, varchar> >) from dwh.table

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

sqlfmt, version 0.20.0

Note: non-breaking, but not ideal

tconbeer commented 10 months ago

We support similar syntax for structs amd arrays in BQ. I think we may just have to add the "map" keyword into that lever.

benjamin-awd commented 10 months ago

Raised a PR https://github.com/tconbeer/sqlfmt/pull/503

benjamin-awd commented 10 months ago

So apparently sqlfluff lints map<...> statements, and actually expects something like this: select cast(json_parse(foo) as array<map <varchar, varchar>>) from dwh.table (note the additional whitespace in front of map)

The specific sqfluff rule is:

L:  57 | P:  57 | LT01 | Expected single whitespace between 'map' keyword and                    
                       | start angle bracket '<'. [layout.spacing]

Not sure if the best solution here is to simply ignore the layout.spacing rule

tconbeer commented 10 months ago

Yeah that makes no sense to have a space after map but not array. I'd ignore that rule.