Skip to content

Commit f3421ba

Browse files
authored
fix: lowercase numbers (#665)
1 parent dcd48b3 commit f3421ba

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
- sqlfmt no longer adds a space between the `*` and `columns` in DuckDB `*columns` expressions ([#657](https://github.com/tconbeer/sqlfmt/issues/657) - thank you [@aersam](https://github.com/aersam)!)
1010
- sqlfmt no longer adds a space between the `:` and `['name']` in a DataBricks escaped variant expression like `foo:['bar.baz']` ([#637](https://github.com/tconbeer/sqlfmt/issues/637) - thank you [@aersam](https://github.com/aersam)!)
1111
- sqlfmt no longer lexes the Postgres operators `#>`, `#>>`, `#-`, and `##` as comments ([#461](https://github.com/tconbeer/sqlfmt/issues/461) - thank you [@pauljz](https://github.com/pauljz) and many others!)
12+
- sqlfmt will now lowercase the letters in a number literal like `".1234567E+2BD` ([#645](https://github.com/tconbeer/sqlfmt/issues/645)).
1213

1314
### Testing
1415
- sqlfmt is now tested against and fully supports Python 3.13

src/sqlfmt/tokens.py

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def is_always_lowercased(self) -> bool:
131131
TokenType.ON,
132132
TokenType.BOOLEAN_OPERATOR,
133133
TokenType.SET_OPERATOR,
134+
TokenType.NUMBER,
134135
]
135136

136137
@cached_property

tests/data/unformatted/132_spark_number_literals.sql

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ select -2147483648 as col
2424
;
2525
select 9223372036854775807l as col
2626
;
27-
select -32Y as col
27+
select -32y as col
2828
;
29-
select 482S as col
29+
select 482s as col
3030
;
3131
select 12.578 as col
3232
;
@@ -36,19 +36,19 @@ select -.1234567 as col
3636
;
3737
select 123. as col
3838
;
39-
select 123.BD as col
39+
select 123.bd as col
4040
;
41-
select 5E2 as col
41+
select 5e2 as col
4242
;
43-
select 5D as col
43+
select 5d as col
4444
;
45-
select -5BD as col
45+
select -5bd as col
4646
;
4747
select 12.578e-2d as col
4848
;
49-
select -.1234567E+2BD as col
49+
select -.1234567e+2bd as col
5050
;
5151
select +3.e+3 as col
5252
;
53-
select -3.E-3D as col
53+
select -3.e-3d as col
5454
;

tests/unit_tests/test_node_manager.py

+16
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ def test_capitalization_operators(default_mode: Mode, source_string: str) -> Non
264264
assert parsed_string.rstrip("\n") == source_string.lower()
265265

266266

267+
@pytest.mark.parametrize(
268+
"source_string",
269+
[
270+
"1e4",
271+
"1E4",
272+
"-.1234567E+2BD",
273+
],
274+
)
275+
def test_capitalization_numbers(default_mode: Mode, source_string: str) -> None:
276+
q = default_mode.dialect.initialize_analyzer(
277+
line_length=default_mode.line_length
278+
).parse_query(source_string=source_string)
279+
parsed_string = "".join(str(line) for line in q.lines)
280+
assert parsed_string.rstrip("\n") == source_string.lower()
281+
282+
267283
@pytest.mark.parametrize(
268284
"source_string",
269285
[

0 commit comments

Comments
 (0)