Comparing a decimal with a negative scale to an integer literal panics in `unwrap_cast`
还没有人认领这个 Issue。
评估
调研方向
从 datafusion/expr-common/src/casts.rs 中的 try_cast_numeric_literal 开始,然后通过 try_cast_literal_to_type 和 unwrap_cast.rs 跟踪其调用方。在 datafusion-cli 的 debug 构建中重现 SQL 查询,并验证负 scale 的 decimal 比较不再 panic,同时将无法表达的 cast 保留在原处。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
try_cast_numeric_literal in datafusion/expr-common/src/casts.rs computes 10_i128.pow(scale as u32) for the target decimal type (and again for a decimal literal's own scale). A negative scale is cast to a huge u32 exponent, so the multiplication overflows and panics in debug builds (wraps in release builds).
The function is reached from the unwrap_cast expression simplifier whenever a cast to a decimal is compared with a numeric literal.
To Reproduce
Debug build of datafusion-cli:
SELECT arrow_cast(1, 'Decimal128(10, -2)') = 100;
thread 'main' panicked at library/core/src/num/mod.rs:475:5:
attempt to multiply with overflow
Backtrace goes through datafusion_expr_common::casts::try_cast_numeric_literal → try_cast_literal_to_type → unwrap_cast.rs.
Expected behavior
No panic. try_cast_literal_to_type already returns None for casts it cannot express; a negative scale (the decimal holds multiples of 10^-scale, so there is no integer 10^scale to rescale by) should be one of them, leaving the cast in place.
Additional context
Found while running a corpus of extreme-value literals against a debug build of datafusion-cli.
- 主要语言
- Rust
- 星标
- 9.3k
- 派生
- 2.4k
- 平均合并
- 3 天 8 小时
- 30 天内合并 PR
- 354
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/datafusion 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
apache/datafusion#25266 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
apache/datafusion#25213 · 1 条评论 ·
-
documentation
难度 2/5 1-3 小时 新手友好度 74/100
apache/datafusion#25168 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
apache/datafusion#24998 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
apache/datafusion#24913 ·
查看 apache/datafusion 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
gitbutlerapp/gitbutler#15998 · 1 条评论 ·
-
bug triage:deciding
难度 1/5 1 小时以内 新手友好度 88/100
open-telemetry/otel-arrow#4132 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 84/100