Skip to content

Return an error for decimal scalars outside the precision - #10767

Open
ump45nose wants to merge 1 commit into
vortex-data:developfrom
ump45nose:fix/10749-decimal-scalar-precision
Open

ump45nose wants to merge 1 commit into
vortex-data:developfrom
ump45nose:fix/10749-decimal-scalar-precision

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Summary

DecimalArray::scalar_at and the decimal min_max aggregate panicked when a stored value did not fit the precision of the dtype, because both built their results with Scalar::decimal, which calls vortex_expect on the precision check. Since DecimalArray construction doesn't check its values and file reads trust the stored precision, a file holding such a value could make a read panic. With this change both calls return an error instead.

This covers the two call sites named in the issue. The other Scalar::decimal callers on read and compute paths (sum, mean, cast, fill_null, between, the DecimalByteParts kernels) are left as they are here; they can move to Scalar::try_decimal in follow-ups once each one is checked.

Changes

  • Add Scalar::try_decimal, a fallible version of Scalar::decimal. Scalar::decimal now calls it and still panics on a bad value, with the panic documented.
  • DecimalArray::scalar_at uses Scalar::try_decimal and returns the error.
  • The decimal min_max aggregate uses Scalar::try_decimal for the min and max and returns the error.
  • New tests test_scalar_at_value_outside_precision_errors and test_decimal_value_outside_precision_errors use the repro from the issue (100i8 with decimal(2, 0)), for one and two values. Both panicked on develop and now return an error.

Tested with cargo test -p vortex-array --lib (4426 passed), cargo clippy -p vortex-array --all-targets --all-features -- -D warnings, and cargo +nightly-2026-09-10 fmt -p vortex-array.

AI assistance: I used an AI coding assistant to help write this change and the description; I reviewed the code and ran the tests above myself.

DecimalArray::scalar_at and the decimal min_max aggregate built their
results with Scalar::decimal, which panics when a stored value does not
fit the precision of the dtype. DecimalArray construction does not check
its values and file reads trust the stored precision, so such a value
could make a read panic.

Add Scalar::try_decimal and use it in both places so they return an
error instead.

Signed-off-by: Vincent <1729065730@qq.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant