tconbeer/sqlfmt

Strange formatting for Athena SQL array/map types

Closed this issue · 4 comments

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

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

Raised a PR #503

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

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