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

Đang mở Phù hợp với người mới
#24,896 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
86/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu trong datafusion/expr-common/src/casts.rs tại try_cast_numeric_literal, sau đó lần theo các caller của nó qua try_cast_literal_to_type và unwrap_cast.rs. Tái hiện truy vấn SQL trong bản debug build của datafusion-cli và xác minh rằng các phép so sánh decimal có scale âm không còn gây panic và giữ nguyên các cast không thể biểu diễn tại chỗ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
9.3k
Fork
2.4k
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
354

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/datafusion

Tất cả issue của apache/datafusion

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.