Skip to content

Commit

Permalink
feat(join-lint): handle left anti join (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
clenost authored Jul 9, 2024
1 parent 3217239 commit 77cce99
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Formatting Changes and Bug Fixes

- Databricks `left anti` & `right anti` joins are now supported.


## [0.21.3] - 2024-04-25

### Bug Fixes
Expand Down
5 changes: 4 additions & 1 deletion src/sqlfmt/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@
r"delete\s+from",
r"from",
r"((cross|positional|semi|anti)\s+)?join",
(r"((natural|asof)\s+)?" r"((inner|(left|right|full)(\s+outer)?)\s+)?join"),
(
r"((natural|asof)\s+)?"
r"((inner|(left|right|full)(\s+(outer|anti))?)\s+)?join"
),
# this is the USING following DELETE, not the join operator
# (see above)
r"using",
Expand Down
6 changes: 4 additions & 2 deletions tests/data/fast/unformatted/104_joins.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
select one.one, two.two,
three.three, four.four, five.five, six.six
three.three, four.four, five.five, six.six, seven.seven
from one
join two on one.two = two.one
inner join "my_database"."my_schema".three as three on one.three = three.one
Expand All @@ -12,9 +12,10 @@ right join (
from my_table where some_filter is true
) as five using(five.id)
natural full outer join six
left anti join seven on one.seven = seven.one
cross join {{ ref('bar_bar_bar') }} as bar
)))))__SQLFMT_OUTPUT__(((((
select one.one, two.two, three.three, four.four, five.five, six.six
select one.one, two.two, three.three, four.four, five.five, six.six, seven.seven
from one
join two on one.two = two.one
inner join "my_database"."my_schema".three as three on one.three = three.one
Expand All @@ -29,4 +30,5 @@ right join
select id, five, six, seven, eight, nine from my_table where some_filter is true
) as five using (five.id)
natural full outer join six
left anti join seven on one.seven = seven.one
cross join {{ ref("bar_bar_bar") }} as bar
6 changes: 4 additions & 2 deletions tests/data/unformatted/104_joins.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
select one.one, two.two,
three.three, four.four, five.five, six.six
three.three, four.four, five.five, six.six, seven.seven
from one
join two on one.two = two.one
inner join "my_database"."my_schema".three as three on one.three = three.one
Expand All @@ -12,9 +12,10 @@ right join (
from my_table where some_filter is true
) as five using(five.id)
natural full outer join six
left anti join seven on one.seven = seven.one
cross join {{ ref('bar_bar_bar') }} as bar
)))))__SQLFMT_OUTPUT__(((((
select one.one, two.two, three.three, four.four, five.five, six.six
select one.one, two.two, three.three, four.four, five.five, six.six, seven.seven
from one
join two on one.two = two.one
inner join "my_database"."my_schema".three as three on one.three = three.one
Expand All @@ -29,4 +30,5 @@ right join
select id, five, six, seven, eight, nine from my_table where some_filter is true
) as five using (five.id)
natural full outer join six
left anti join seven on one.seven = seven.one
cross join {{ ref("bar_bar_bar") }} as bar
2 changes: 2 additions & 0 deletions tests/unit_tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule:
(MAIN, "unterm_keyword", "asof left join"),
(MAIN, "unterm_keyword", "asof right\n outer\n join"),
(MAIN, "unterm_keyword", "semi join"),
(MAIN, "unterm_keyword", "left anti join"),
(MAIN, "unterm_keyword", "right anti join"),
(MAIN, "unterm_keyword", "anti join"),
(MAIN, "unterm_keyword", "join"),
(MAIN, "unterm_keyword", "values"),
Expand Down

0 comments on commit 77cce99

Please sign in to comment.