Skip to content
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
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/io/range_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def position_to_fraction(
istart = cls._bytestring_to_int(start, prec)
ikey = cls._bytestring_to_int(key, prec)
iend = cls._bytestring_to_int(end, prec) if end else 1 << (prec * 8)
return float(ikey - istart) / (iend - istart)
return (ikey - istart) / (iend - istart)

@staticmethod
def _bytestring_to_int(s: Union[bytes, str], prec: int) -> int:
Expand Down
7 changes: 7 additions & 0 deletions sdks/python/apache_beam/io/range_trackers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ def test_key_to_fraction_common_prefix(self):
end='a' * 100 + 'e',
fraction=1.0)

def test_key_to_fraction_long_keys(self):
for start, key, end in (
(b'a' * 400, b'm' * 400, b'z' * 400),
('a' * 400, 'm' * 400, 'z' * 400)):
with self.subTest(key_type=type(key).__name__):
self.assertAlmostEqual(0.48, self.key_to_fraction(key, start, end))

def test_tiny(self):
# test bytes keys
self._check(fraction=.5**20, key=b'\0\0\x10')
Expand Down
Loading