XiaoMingFa opened a new pull request, #26955: URL: https://github.com/apache/datafusion/pull/26955
## Which issue does this PR close? Closes #26950. ## Rationale for this change When evaluating `ceil` or `floor` on a decimal scalar argument, the scalar is converted into an array to reuse the decimal operator and precision/scale calculations, and the resulting scalar is then extracted from index 0. Previously, `arg.to_array(args.number_rows)` was used. When `args.number_rows == 0`, this produced an empty `PrimitiveArray` of length 0, causing `ScalarValue::try_from_array(&result, 0)` to panic: ```text Trying to access an element at index 0 from a PrimitiveArray of length 0 ``` Furthermore, the architectural comment in both functions explicitly noted: > `// For decimals: convert to array of size 1, process, then extract scalar` > `// This ensures we don't expand the array while reusing overflow validation` Using `args.number_rows` instead of 1 defeated this optimization when `args.number_rows > 1` and panicked when `args.number_rows == 0`. ## What changes are included in this PR? - In `ceil.rs` and `floor.rs`, when `is_scalar` is true, convert the scalar to an array of size 1 (`arg.to_array(1)`). - Preserve `arg.to_array(args.number_rows)` for array inputs (`is_scalar == false`). - Added unit regression tests for both `ceil` and `floor` covering decimal scalars evaluated with `number_rows: 0`. ## Are these changes tested? Yes, new unit tests `test_ceil_decimal_scalar_zero_rows` and `test_floor_decimal_scalar_zero_rows` verify this behavior and pass. All existing math tests continue to pass. ## Are there any user-facing changes? No breaking changes. Fixes panics when `ceil` or `floor` is called with decimal scalars under zero rows. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
