Comparing a decimal with a negative scale to an integer literal panics in `unwrap_cast`

未关闭 适合新手
#24,896 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
databases

调研方向

从 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_literaltry_cast_literal_to_typeunwrap_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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion 的其他 Issue

查看 apache/datafusion 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。