1fanwang opened a new pull request, #25179: URL: https://github.com/apache/datafusion/pull/25179
## Which issue does this PR close? None; found by sweeping the scalar functions with edge-case arguments. ## Rationale for this change `array_resize` with a negative size raises an internal error, which tells the caller they hit a DataFusion bug and asks them to open a report: ```console > SELECT array_resize(make_array(1,2,3), -1, 0); Internal error: array_resize: failed to convert size to usize. This issue was likely caused by a bug in DataFusion's code. Please help us to resolve this by filing a bug report in our issue tracker: https://github.com/apache/datafusion/issues ``` The size is an argument to the query, so a negative value is the caller's input rather than a broken internal invariant. Sending someone to the issue tracker for their own argument is misleading, and it hides what was actually wrong. The behaviour was already meant to be an error. `array_resize.slt` has expected this call to fail since before this change, but with a bare `query error`, so the internal error satisfied it and went unnoticed. ## What changes are included in this PR? Reject a negative size with an execution error naming the value, which matches how the neighbouring maximum-size check already reports bad input: ```console > SELECT array_resize(make_array(1,2,3), -1, 0); Execution error: array_resize: size must not be negative, got -1 ``` Valid input is untouched: `0` still returns `[]`, `5` still grows to `[1, 2, 3, 9, 9]`, and a NULL size still returns NULL. ## Are these changes tested? Yes. The slt file gains the negative case for both `List` and `LargeList`, plus `i64::MIN` for the boundary, each pinned to the new message so a regression back to an internal error fails the suite. ```console $ cargo test -p datafusion-sqllogictest --test sqllogictests -- array Progress: 53/53 files completed (100%) $ cargo test -p datafusion-functions-nested --lib resize test result: ok. 4 passed; 0 failed ``` The pre-existing `query error` case for `-5` still passes, so the contract that a negative size fails is unchanged. ## Are there any user-facing changes? The error for a negative size changes from an internal error to an execution error with a clear message. No valid call changes behaviour, and no API changes. -- 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]
