Skip to content

Commit

Permalink
fix #483: no space in any() or all()
Browse files Browse the repository at this point in the history
  • Loading branch information
tconbeer committed Sep 25, 2023
1 parent 76dbbb1 commit 781ff3d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.

- Drops support for Python 3.7. Please upgrade to Python 3.8 or higher.

### Formatting Changes and Bug Fixes

- `any()` and `all()` will no longer get spaces between the function name and the parenthesis, unless they are a part of a `like any ()` or `like all ()` operator ([#483](https://github.com/tconbeer/sqlfmt/issues/483) - thank you [@damirbk](https://github.com/damirbk)!).

## [0.19.2] - 2023-07-31

### Bug Fixes
Expand Down
4 changes: 1 addition & 3 deletions src/sqlfmt/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
name="word_operator",
priority=1100,
pattern=group(
r"all",
r"any",
r"as",
r"(not\s+)?between",
r"cube",
Expand All @@ -53,7 +51,7 @@
r"(not\s+)?in",
r"is(\s+not)?(\s+distinct\s+from)?",
r"isnull",
r"(not\s+)?i?like(\s+any)?",
r"(not\s+)?i?like(\s+(any|all))?",
r"over",
r"(un)?pivot",
r"notnull",
Expand Down
21 changes: 21 additions & 0 deletions tests/data/unformatted/219_any_all_agg.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

-- source: https://github.com/tconbeer/sqlfmt/issues/483
select any(number) as any_number from (select number from system.numbers limit 10);
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);
select foo from bar where foo like all (baz) or foo like any (qux);
)))))__SQLFMT_OUTPUT__(((((
-- source: https://github.com/tconbeer/sqlfmt/issues/483
select any(number) as any_number
from (select number from system.numbers limit 10)
;
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)
;
select foo
from bar
where foo like all (baz) or foo like any (qux)
;
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 @@ -63,6 +63,7 @@
"unformatted/216_gitlab_zuora_revenue_revenue_contract_line_source.sql",
"unformatted/217_dbt_unit_testing_csv.sql",
"unformatted/218_multiple_c_comments.sql",
"unformatted/219_any_all_agg.sql",
"unformatted/300_jinjafmt.sql",
"unformatted/400_create_fn_and_select.sql",
"unformatted/401_explain_select.sql",
Expand Down
6 changes: 4 additions & 2 deletions tests/unit_tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule:
(MAIN, "word_operator", "not ilike"),
(MAIN, "word_operator", "like any"),
(MAIN, "word_operator", "not like any"),
(MAIN, "word_operator", "any"),
(MAIN, "word_operator", "like all"),
(MAIN, "word_operator", "not like all"),
(MAIN, "word_operator", "some"),
(MAIN, "word_operator", "exists"),
(MAIN, "word_operator", "not exists"),
(MAIN, "word_operator", "all"),
(MAIN, "word_operator", "grouping sets"),
(MAIN, "word_operator", "cube"),
(MAIN, "word_operator", "rollup"),
Expand Down Expand Up @@ -360,6 +360,8 @@ def test_regex_exact_match(
(CORE, "other_identifiers", "?"),
(CORE, "operator", "."),
(MAIN, "word_operator", "using"),
(MAIN, "word_operator", "any"),
(MAIN, "word_operator", "all"),
(MAIN, "unterm_keyword", "lateral flatten"),
(MAIN, "unterm_keyword", "for"),
(MAIN, "unterm_keyword", "MAIN into"),
Expand Down

0 comments on commit 781ff3d

Please sign in to comment.