diff --git a/CHANGELOG.md b/CHANGELOG.md index d0aa67e9..77237a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/sqlfmt/rules/__init__.py b/src/sqlfmt/rules/__init__.py index 1b3b7d37..d97ee2f8 100644 --- a/src/sqlfmt/rules/__init__.py +++ b/src/sqlfmt/rules/__init__.py @@ -42,8 +42,6 @@ name="word_operator", priority=1100, pattern=group( - r"all", - r"any", r"as", r"(not\s+)?between", r"cube", @@ -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", diff --git a/tests/data/unformatted/219_any_all_agg.sql b/tests/data/unformatted/219_any_all_agg.sql new file mode 100644 index 00000000..fb865d9b --- /dev/null +++ b/tests/data/unformatted/219_any_all_agg.sql @@ -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) +; diff --git a/tests/functional_tests/test_general_formatting.py b/tests/functional_tests/test_general_formatting.py index 83dbb2d7..9382563f 100644 --- a/tests/functional_tests/test_general_formatting.py +++ b/tests/functional_tests/test_general_formatting.py @@ -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", diff --git a/tests/unit_tests/test_rule.py b/tests/unit_tests/test_rule.py index 438db142..1e09360b 100644 --- a/tests/unit_tests/test_rule.py +++ b/tests/unit_tests/test_rule.py @@ -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"), @@ -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"),