StringLiteral to IntegerType/LongType silently truncates fractional strings, changing predicate meaning
维护者通常 1 天内回复
评估
调研方向
问题出在 pyiceberg/expressions/literals.py 中 IntegerType 和 LongType 的 StringLiteral.to() 转换上。它应当走 DecimalLiteral 已在使用的现有辅助函数 _to_integral。请先复现 literal("2.6").to(IntegerType()),然后阅读 tests/expressions/test_literals.py 中的 test_string_literal。完成的标准是:对于两种整数类型,带小数的字符串都抛出 ValueError,而 "2.0" 和 "1e3" 这类整数字符串仍能被精确转换。
由索引模型根据 Issue 内容生成。
描述
Apache Iceberg version
0.12.0 (latest release)
Please describe the bug 🐞
literal("2.6").to(IntegerType()) returns LongLiteral(2) instead of raising, while DecimalLiteral(Decimal("2.6")).to(IntegerType()) raises ValueError. A bound predicate such as x < "2.6" on an int column therefore becomes x < 2 and wrongly drops rows with x = 2 (verified with expression_evaluator); the same bound literal feeds partition pruning, so files can be skipped too.
The sibling DecimalLiteral.to(IntegerType/LongType) already rejects fractional values via the existing _to_integral helper, with a test spelling out why: rounding would change the predicate (e.g. x > 2.6 becoming x > 3 drops x = 3). The StringLiteral path was missed. The reference Java implementation has no INTEGER/LONG case in StringLiteral.to() and refuses the conversion.
Suggested fix: use the existing _to_integral helper in both StringLiteral.to(IntegerType) and StringLiteral.to(LongType), and update test_string_literal to expect ValueError for fractional strings.
Reproduction (pyiceberg 0.12.0, main @ fce8185):
literal("2.6").to(IntegerType())returnsLongLiteral(2); same for LongTypeliteral("-2.5").to(IntegerType())returnsLongLiteral(-2);literal("0.1").to(LongType())returnsLongLiteral(0)LessThan("x", "2.6")bound to an int column becomesx < 2, andexpression_evaluatorreturns False for a row with x = 2, although x < 2.6 is True- Integral strings still convert exactly:
literal("2.0").to(IntegerType())returns 2,literal("1e3").to(IntegerType())returns 1000
Willingness to contribute
- I can contribute a fix for this bug independently
- I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- I cannot contribute a fix for this bug at this time
- 主要语言
- Python
- 星标
- 1.2k
- 派生
- 664
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 131
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/iceberg-python 的其他 Issue
-
`inspect.files()` and the other file metadata tables raise `ArrowInvalid` when a snapshot has no manifests可能已有人在做 @YuangGao 于 12 天前认领。 未关闭kind:bug
难度 2/5 1-3 小时 新手友好度 72/100
apache/iceberg-python#4269 ·
维护者通常 1 天内回复
-
`inspect.entries()` raises TypeError when a data file has no column_sizes可能已有人在做 @Rahul-cs50 于 15 天前认领。 未关闭kind:bug
难度 2/5 1-3 小时 新手友好度 78/100
apache/iceberg-python#4186 · 2 条评论 ·
维护者通常 1 天内回复
-
`older_than` reads a naive datetime as UTC and expires snapshots it should keep可能已有人在做 @Rahul-cs50 于 14 天前认领。 未关闭kind:bug
难度 2/5 1-3 小时 新手友好度 72/100
apache/iceberg-python#4182 · 1 条评论 ·
维护者通常 1 天内回复
-
REST: Send empty first-page pageToken when rest-page-size is set可能已有人在做 @ehddnr301 于 33 天前认领。 未关闭kind:bug
难度 2/5 1-3 小时 新手友好度 82/100
apache/iceberg-python#4096 ·
维护者通常 1 天内回复
-
PyArrowFileIO: every small S3 write is a 3-request multipart upload; expose allow_delayed_open可能已有人在做 @David-Banquet 于 30 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
apache/iceberg-python#4093 · 3 条评论 ·
维护者通常 1 天内回复
查看 apache/iceberg-python 的全部 Issue
相似的 Issue
-
ライブラリを追加未关闭priority middle
难度 1/5 1 小时以内 新手友好度 62/100
KATO-Hiro/AtCoderClans#13015 ·
维护者通常 1 天内回复
-
request-theme
难度 2/5 1 小时以内 新手友好度 62/100
LizardByte/ThemerrDB#10024 · 2 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 72/100
btclib-org/btclib-node#2505 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
open-webui/open-webui#34462 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
KLayout/klayout#2554 · 1 条评论 ·
维护者通常 1 天内回复