This is an automated email from the ASF dual-hosted git repository.
jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new f66e0ceea03 Fix overflow in LexicographicKeyRangeTracker (#40330)
f66e0ceea03 is described below
commit f66e0ceea0360b02d6ff2da931740f46d1ffea6b
Author: Goutam Adwant <[email protected]>
AuthorDate: Tue Sep 29 08:00:26 2026 -0700
Fix overflow in LexicographicKeyRangeTracker (#40330)
---
sdks/python/apache_beam/io/range_trackers.py | 2 +-
sdks/python/apache_beam/io/range_trackers_test.py | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/sdks/python/apache_beam/io/range_trackers.py
b/sdks/python/apache_beam/io/range_trackers.py
index 626564b0094..7f6b5350288 100644
--- a/sdks/python/apache_beam/io/range_trackers.py
+++ b/sdks/python/apache_beam/io/range_trackers.py
@@ -429,7 +429,7 @@ class
LexicographicKeyRangeTracker(OrderedPositionRangeTracker):
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:
diff --git a/sdks/python/apache_beam/io/range_trackers_test.py
b/sdks/python/apache_beam/io/range_trackers_test.py
index 0bf37997f2c..8b829616bf5 100644
--- a/sdks/python/apache_beam/io/range_trackers_test.py
+++ b/sdks/python/apache_beam/io/range_trackers_test.py
@@ -432,6 +432,13 @@ class LexicographicKeyRangeTrackerTest(unittest.TestCase):
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')