Skip to content

Commit

Permalink
fix #417: parse union distinct correctly (#420)
Browse files Browse the repository at this point in the history
* fix #417: parse union distinct correctly

* chore: bump primer refs
  • Loading branch information
tconbeer committed May 10, 2023
1 parent 3d6db76 commit b50aec9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to this project will be documented in this file.

## [Unreleased]
- fixes a bug when lexing `union distinct` tokens ([#417](https://github.com/tconbeer/sqlfmt/issues/417) - thank you, [@paschmaria](https://github.com/paschmaria)!)

## [0.18.0] - 2023-04-19

Expand Down
2 changes: 1 addition & 1 deletion src/sqlfmt/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
name="set_operator",
priority=1320,
pattern=group(
r"(union|intersect|except|minus)(\s+all|distinct)?",
r"(union|intersect|except|minus)(\s+(all|distinct))?",
)
+ group(r"\W", r"$"),
action=actions.handle_set_operator,
Expand Down
2 changes: 1 addition & 1 deletion src/sqlfmt_primer/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_projects() -> List[SQLProject]:
SQLProject(
name="dbt_utils",
git_url="https://github.com/tconbeer/dbt-utils.git",
git_ref="ae160c9", # sqlfmt 54b8edd
git_ref="c62b99f", # sqlfmt 6e9615c
expected_changed=0,
expected_unchanged=131,
expected_errored=0,
Expand Down
6 changes: 6 additions & 0 deletions tests/data/unformatted/114_unions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ SELECT *, 'mr' AS geo_code, 'Mauritania' AS geo, 'Africa' AS region, 'Western Af
SELECT *, 'mu' AS geo_code, 'Mauritius' AS geo, 'Africa' AS region, 'Eastern Africa' AS subregion FROM `chrome-ux-report.country_mu.201907` UNION ALL
SELECT *, 'yt' AS geo_code, 'Mayotte' AS geo, 'Africa' AS region, 'Eastern Africa' AS subregion FROM `chrome-ux-report.country_yt.201907`
) select geo from geos
union distinct
select *
from foo
)))))__SQLFMT_OUTPUT__(((((
(
select *
Expand Down Expand Up @@ -113,3 +116,6 @@ with
)
select geo
from geos
union distinct
select *
from foo
1 change: 1 addition & 0 deletions tests/unit_tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule:
(MAIN, "unterm_keyword", "delete from"),
(MAIN, "set_operator", "union"),
(MAIN, "set_operator", "union all"),
(MAIN, "set_operator", "union distinct"),
(MAIN, "set_operator", "intersect"),
(MAIN, "set_operator", "minus"),
(MAIN, "set_operator", "except"),
Expand Down

0 comments on commit b50aec9

Please sign in to comment.