Comparing a decimal with a negative scale to an integer literal panics in `unwrap_cast`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
Research direction
Start in datafusion/expr-common/src/casts.rs at try_cast_numeric_literal, then follow its callers through try_cast_literal_to_type and unwrap_cast.rs. Reproduce the SQL query in a debug build of datafusion-cli and verify that negative-scale decimal comparisons no longer panic and leave unexpressible casts in place.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 354
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/datafusion
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
apache/datafusion#25266 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion#25213 · 1 comment ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
apache/datafusion#25168 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
apache/datafusion#24998 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/datafusion#24913 ·
All issues in apache/datafusion
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·