Skip to content

Commit

Permalink
fix #500: handle athena map data type
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd authored and tconbeer committed Oct 20, 2023
1 parent 614f526 commit 3674e2f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/sqlfmt/node_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def raise_on_mismatched_bracket(self, token: Token, last_bracket: Node) -> None:
"[": "]",
"case": "end",
"array<": ">",
"map<": ">",
"table<": ">",
"struct<": ">",
}
Expand Down
4 changes: 2 additions & 2 deletions src/sqlfmt/rules/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
r"\[",
r"\(",
r"\{",
# bq usese angle brackets for type definitions for compound types
r"(array|table|struct)\s*<",
# bq/athena uses angle brackets for type definitions for compound types
r"(array|map|table|struct)\s*<",
),
action=partial(actions.add_node_to_buffer, token_type=TokenType.BRACKET_OPEN),
),
Expand Down
9 changes: 9 additions & 0 deletions tests/data/unformatted/130_athena_data_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- source: https://github.com/tconbeer/sqlfmt/issues/500
select
cast(
json_parse(foo) as array<
map<varchar,varchar>>)
from dwh.table
)))))__SQLFMT_OUTPUT__(((((
-- source: https://github.com/tconbeer/sqlfmt/issues/500
select cast(json_parse(foo) as array<map<varchar, varchar>>) from dwh.table
1 change: 1 addition & 0 deletions tests/functional_tests/test_general_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"unformatted/127_more_comments.sql",
"unformatted/128_double_slash_comments.sql",
"unformatted/129_duckdb_joins.sql",
"unformatted/130_athena_data_types.sql",
"unformatted/200_base_model.sql",
"unformatted/201_basic_snapshot.sql",
"unformatted/202_unpivot_macro.sql",
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule:
(MAIN, "set_operator", "minus"),
(MAIN, "set_operator", "except"),
(CORE, "bracket_open", "array<"),
(CORE, "bracket_open", "map<"),
(CORE, "bracket_open", "table\n<"),
(CORE, "bracket_open", "struct<"),
(MAIN, "explain", "explain"),
Expand Down

0 comments on commit 3674e2f

Please sign in to comment.