Skip to content

Commit

Permalink
fix/issue 218/support using (#226)
Browse files Browse the repository at this point in the history
* fix #218: add a space between using and bracket

* chore: update primer and changelog
  • Loading branch information
tconbeer authored Aug 2, 2022
1 parent fb3253f commit e2c30ac
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Formatting Changes + Bug Fixes

- sqlfmt now standardizes whitespace inside word tokens ([#201](https://github.com/tconbeer/sqlfmt/issues/201))
- `using` is now treated as a word operator. It gets a space before its brackets and merging with surrounding lines is now much improved ([#218](https://github.com/tconbeer/sqlfmt/issues/218) - thank you [@nfcampos](https://github.com/nfcampos)!)

## [0.10.0] - 2022-08-02

Expand Down
1 change: 1 addition & 0 deletions src/sqlfmt/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def __init__(self) -> None:
r"(not\s+)?rlike",
r"some",
r"(not\s+)?similar\s+to",
r"using",
)
+ group(r"\W", r"$"),
action=partial(
Expand Down
4 changes: 2 additions & 2 deletions src/sqlfmt_primer/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_projects() -> List[SQLProject]:
SQLProject(
name="rittman",
git_url="https://github.com/tconbeer/rittman_ra_data_warehouse.git",
git_ref="44bb35dd4db50e4113cac8cb8d3521da8d998e1d", # sqlfmt 49fa97e
git_ref="1315cdb9aeff129a16e6be0ba5696c040058a34c", # sqlfmt 5b2d861
expected_changed=0,
expected_unchanged=307,
expected_errored=4, # true mismatching brackets
Expand All @@ -48,7 +48,7 @@ def get_projects() -> List[SQLProject]:
SQLProject(
name="http_archive",
git_url="https://github.com/tconbeer/http_archive_almanac.git",
git_ref="797b34f6792e194fdb934cdb806884a795bdb71c", # sqlfmt fb99833
git_ref="fe1ffff709007841f06c3feef19d5bd28f3c8c62", # sqlfmt 5b2d861
expected_changed=1,
expected_unchanged=1701,
expected_errored=0,
Expand Down
6 changes: 3 additions & 3 deletions tests/data/unformatted/104_joins.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ left outer join four on
and three.four = four.three
and something_else
right join (
select id, five, six, seven, eight
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
Expand All @@ -26,7 +26,7 @@ left outer join
and something_else
right join
(
select id, five, six, seven, eight from my_table where some_filter is true
) as five using(five.id)
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
cross join {{ ref("bar_bar_bar") }} as bar
16 changes: 8 additions & 8 deletions tests/data/unformatted/115_select_star_except.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ select
recentagg_topactivities_array.topactivities,
) recentagg,
from recentagg_root
left join recentagg_topphases_array using(id)
left join recentagg_topsymptoms_array using(id)
left join recentagg_toppositivesymptoms_array using(id)
left join recentagg_topactivities_array using(id)
left join recentagg_topphases_array using (id)
left join recentagg_topsymptoms_array using (id)
left join recentagg_toppositivesymptoms_array using (id)
left join recentagg_topactivities_array using (id)
)))))__SQLFMT_OUTPUT__(((((
select
* except (field_a, field_b, field_c),
Expand Down Expand Up @@ -71,7 +71,7 @@ select
recentagg_topactivities_array.topactivities,
) recentagg,
from recentagg_root
left join recentagg_topphases_array using(id)
left join recentagg_topsymptoms_array using(id)
left join recentagg_toppositivesymptoms_array using(id)
left join recentagg_topactivities_array using(id)
left join recentagg_topphases_array using (id)
left join recentagg_topsymptoms_array using (id)
left join recentagg_toppositivesymptoms_array using (id)
left join recentagg_topactivities_array using (id)
4 changes: 1 addition & 3 deletions tests/data/unformatted/212_http_2019_cms_14_02.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ inner join
select _table_suffix as client, url
from `httparchive.technologies.2019_07_01_*`
where app = 'WordPress'
)
using
(client, url)
) using (client, url)
group by client, amp_plugin_mode
order by freq / total desc
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ left join
(
select one_field, two_fields, sum(something), my_very_long_field_name
from another_table
) as mysubquery using(id)
) as mysubquery using (id)
1 change: 1 addition & 0 deletions tests/unit_tests/test_node_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def test_identifier_whitespace(default_mode: Mode, source_string: str) -> None:
"(())\n",
"([])\n",
"()[] + foo()[offset(1)]\n",
"using (id)\n",
],
)
def test_bracket_whitespace(default_mode: Mode, source_string: str) -> None:
Expand Down

0 comments on commit e2c30ac

Please sign in to comment.