Commit 75cd77f
authored
Fix precision loss in large integral string conversions (#3405)
## Summary
Fixes precision loss when converting large integral strings in two
runtime paths:
- `StringLiteral.to(IntegerType/LongType)`
- `partition_to_py(...)` for integral and time-based partition values
backed by integers
## Root cause
Both paths were converting through `float` before converting to `int`,
which loses precision for values outside the IEEE-754 exact integer
range.
That caused valid 64-bit integers like `LongType.max` and
`9007199254740993` to be corrupted.
## What changed
- Replaced `int(float(...))` with exact integer parsing in
`partition_to_py`
- For `StringLiteral.to(IntegerType/LongType)`, exact integral strings
now use exact integer parsing while fractional numeric strings retain
the existing truncation behavior
- Added regression tests for `LongType.max` and `9007199254740993`
## Validation
- `uv run pytest tests/expressions/test_literals.py
tests/test_conversions.py`
Closes #3404.1 parent b7ca7be commit 75cd77f
4 files changed
Lines changed: 50 additions & 7 deletions
File tree
- pyiceberg
- expressions
- tests
- expressions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
71 | 78 | | |
72 | 79 | | |
73 | 80 | | |
| |||
555 | 562 | | |
556 | 563 | | |
557 | 564 | | |
558 | | - | |
| 565 | + | |
559 | 566 | | |
560 | 567 | | |
561 | 568 | | |
562 | 569 | | |
563 | 570 | | |
564 | | - | |
565 | | - | |
| 571 | + | |
| 572 | + | |
566 | 573 | | |
567 | 574 | | |
568 | 575 | | |
569 | 576 | | |
570 | 577 | | |
571 | | - | |
| 578 | + | |
572 | 579 | | |
573 | 580 | | |
574 | 581 | | |
575 | 582 | | |
576 | 583 | | |
577 | | - | |
578 | | - | |
| 584 | + | |
| 585 | + | |
579 | 586 | | |
580 | 587 | | |
581 | 588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
845 | 846 | | |
846 | 847 | | |
847 | 848 | | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
848 | 881 | | |
849 | 882 | | |
850 | 883 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
163 | 165 | | |
164 | 166 | | |
| 167 | + | |
165 | 168 | | |
166 | 169 | | |
167 | 170 | | |
| |||
0 commit comments