dtenedor opened a new pull request, #53823: URL: https://github.com/apache/spark/pull/53823
### What changes were proposed in this pull request? This PR fixes error handling in `HllUnionAgg` to properly catch `ArrayIndexOutOfBoundsException` and convert it to the user-friendly `HLL_INVALID_INPUT_SKETCH_BUFFER` error. When an invalid HLL sketch binary is passed to `HllUnionAgg`, the DataSketches library may throw an `ArrayIndexOutOfBoundsException` during parsing. For example, if the `curMode` ordinal in the HLL preamble is set to an invalid value (e.g., 3 when only 0, 1, 2 are valid), `CurMode.fromOrdinal()` throws this exception. Previously, this exception would propagate to the user as an unhelpful `ArrayIndexOutOfBoundsException`. The fix adds `ArrayIndexOutOfBoundsException` to the existing catch block that already handles `SketchesArgumentException` and `java.lang.Error`, ensuring all invalid sketch buffer errors are converted to the clear `HLL_INVALID_INPUT_SKETCH_BUFFER` error message. ### Why are the changes needed? Without this fix, users see a confusing `ArrayIndexOutOfBoundsException` when passing malformed binary data to HLL union functions. This provides a poor user experience as it doesn't indicate what went wrong or how to fix it. The `HLL_INVALID_INPUT_SKETCH_BUFFER` error clearly indicates that the input binary is not a valid HLL sketch. ### Does this PR introduce _any_ user-facing change? Yes. Users who pass invalid binary data to `hll_union_agg` will now see a clear error message (`HLL_INVALID_INPUT_SKETCH_BUFFER`) instead of an `ArrayIndexOutOfBoundsException`. ### How was this patch tested? Added a new unit test `"HllUnionAgg throws proper error for invalid binary input causing ArrayIndexOutOfBounds"` in `DatasketchesHllSketchSuite` that: 1. Crafts a byte array with a valid HLL preamble structure but an invalid `curMode` ordinal (3 instead of 0, 1, or 2) 2. Verifies that the exception is NOT an `ArrayIndexOutOfBoundsException` 3. Verifies that the error message contains `HLL_INVALID_INPUT_SKETCH_BUFFER` ### Was this patch authored or co-authored using generative AI tooling? Yes, `claude-4.5-opus-high` plus manual review and editing. -- 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]
