Skip to content

Commit a74a270

Browse files
committed
chore: remove unused function and test
We used to have this when we were caring about id order in the dbs but we don't anymore cause cba, so i'm not sure why this is still here.
1 parent 709bdd5 commit a74a270

File tree

2 files changed

+0
-58
lines changed

2 files changed

+0
-58
lines changed

dataimporter/lib/dbs.py

-38
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,10 @@
44

55
import msgpack
66
import plyvel
7-
from fastnumbers import check_int
87
from splitgill.utils import parse_to_timestamp, now, partition
98

109
from dataimporter.lib.model import SourceRecord
1110

12-
# the maximum integer we can represent as a sortable string is 78 digits
13-
MAX_INT = int("9" * 78)
14-
15-
16-
def int_to_sortable_str(number: int) -> str:
17-
"""
18-
Encodes the given number and returns a string that when compared to other strings is
19-
alphanumerically orderable. This fixes the standard 1, 2, 20, 21, 3 problem without
20-
using zero padding which wastes space and requires a much lower maximum input value.
21-
The algorithm used is based on the one presented here:
22-
https://www.arangodb.com/2017/09/sorting-number-strings-numerically/ with a couple
23-
of tweaks.
24-
25-
Essentially, we encode the length of the number before the number itself using a
26-
single ASCII character. This allows sorting to be done properly as the ASCII
27-
character is compared first and then the number next. For example, the number 1 gets
28-
the character 1 so is encoded as "1_1", whereas 10 gets the character 2 and is
29-
encoded "2_10". Because we are restricted to not use . in keys and for low number
30-
convenience, we start at character point 49 which is the character 1 and therefore
31-
all numbers less than 1,000,000,000 are encoded with the numbers 1 to 9 which is
32-
convenient for users.
33-
34-
This encoding structure can support a number with a maximum length of 78 digits
35-
(ASCII char 1 (49) to ~ (126)).
36-
37-
This function only works on positive integers. If the input isn't valid, a
38-
ValueError is raised.
39-
40-
:param number: the number to encode, must be positive
41-
:return: the encoded number as a str object
42-
"""
43-
if not check_int(number):
44-
raise ValueError("Number must be a valid integer")
45-
if number < 0 or number > MAX_INT:
46-
raise ValueError(f"Number must be positive and no more than {MAX_INT}")
47-
return f"{chr(48 + len(str(number)))}_{number}"
48-
4911

5012
class DB:
5113
"""

tests/test_dbs.py

-20
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,11 @@
1515
Index,
1616
ChangeQueue,
1717
EmbargoQueue,
18-
int_to_sortable_str,
19-
MAX_INT,
2018
RedactionDB,
2119
)
2220
from dataimporter.lib.model import SourceRecord
2321

2422

25-
def test_int_to_sortable_str():
26-
with pytest.raises(ValueError):
27-
assert int_to_sortable_str(20.5)
28-
29-
with pytest.raises(ValueError):
30-
assert int_to_sortable_str(20.0)
31-
32-
with pytest.raises(ValueError):
33-
assert int_to_sortable_str(-1)
34-
35-
with pytest.raises(ValueError):
36-
assert int_to_sortable_str(MAX_INT + 1)
37-
38-
assert int_to_sortable_str(10) == "2_10"
39-
assert int_to_sortable_str(0) == "1_0"
40-
assert int_to_sortable_str(MAX_INT - 1) == f"~_{MAX_INT - 1}"
41-
42-
4323
class TestDB:
4424
def test_name(self, tmp_path: Path):
4525
db = DB(tmp_path / "database")

0 commit comments

Comments
 (0)