Skip to content

Commit

Permalink
fix #637: no space between a colon and square bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
tconbeer committed Jan 24, 2025
1 parent 7caa359 commit dc00efa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/sqlfmt/node_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ def whitespace(
)
):
return NO_SPACE
# open square brackets that follow colons are escaped databricks
# variant cols
elif (
token.type is TokenType.BRACKET_OPEN
and token.token == "["
and previous_token
and previous_token.type is TokenType.COLON
):
return NO_SPACE
# need a space before any other open bracket
elif token.type is TokenType.BRACKET_OPEN:
return SPACE
Expand Down
6 changes: 6 additions & 0 deletions tests/data/unformatted/136_databricks_variant.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- https://github.com/tconbeer/sqlfmt/issues/637
SELECT e.col:['attr_ID']::string as id
FROM expl e
)))))__SQLFMT_OUTPUT__(((((
-- https://github.com/tconbeer/sqlfmt/issues/637
select e.col:['attr_ID']::string as id from expl e
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 @@ -56,6 +56,7 @@
"unformatted/133_for_else.sql",
"unformatted/134_databricks_type_hints.sql",
"unformatted/135_star_columns.sql",
"unformatted/136_databricks_variant.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_node_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def test_identifier_whitespace(default_mode: Mode, source_string: str) -> None:
"([])\n",
"()[] + foo()[offset(1)]\n",
"using (id)\n",
"foo:['bar.baz']\n",
],
)
def test_bracket_whitespace(default_mode: Mode, source_string: str) -> None:
Expand Down

0 comments on commit dc00efa

Please sign in to comment.