Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(join-lint): handle left anti join #607

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading