Repository navigation
GH-55780: [C++] Raise instead of crashing in array_filter and array_take with mixed scalar and array arguments - #55781
Open
Chetansahney wants to merge 2 commits into
Open
Chetansahney wants to merge 2 commits into
Chetansahney wants to merge 2 commits into
Conversation
…rray_take with mixed scalar and array arguments
…scalar and array arguments
2 of 5 tasks
Author
|
I've added Python tests in bd9a129: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
filter,array_filterandarray_takecrash the process when scalar and array arguments are mixed:The vector executor only promotes scalar arguments to arrays when all arguments are scalars. In the mixed case the scalar reaches the selection kernels, which read both arguments as arrays.
filtercrashes because it passes scalar values on toarray_filter.What changes are included in this PR?
array_filterandarray_takeare now registered as a smallVectorFunctionsubclass that checks the argument kinds inExecuteand returnsTypeErrorwhen scalars and arrays are mixed. Putting the check there covers every selection kernel at once, instead of adding it to each of the type-specific exec functions. When all arguments are scalars they are still promoted to length-1 arrays, so that case is unchanged.takealready rejected scalar indices itself, so its behavior is unchanged.Are these changes tested?
Yes. The new
TestFilterKernel.MixedScalarAndArrayArgumentsandTestTakeKernel.MixedScalarAndArrayArgumentscover scalar values with array selection and array values with scalar selection forfilter,array_filterandarray_take, and check that all-scalar input still returns a length-1 array.Run locally on Windows (MSVC, Release). Without the change, both new tests fail with an access violation (
SEH exception with code 0xc0000005). With it, they pass, andarrow-compute-vector-selection-test(170 tests) andarrow-compute-vector-testpass in full.Python:
test_array_take_mixed_scalar_and_array_argumentsandtest_array_filter_mixed_scalar_and_array_argumentsintest_compute.pycheck theTypeErrorfor mixed arguments toarray_take,array_filterandfilter, and the all-scalar case. With pyarrow 26.0.1 both crash the interpreter (access violation); with pyarrow built from this branch they pass.Are there any user-facing changes?
The calls above now raise
ArrowTypeErrorinstead of crashing.This PR contains a "Critical Fix". It fixes a crash (segmentation fault) on user input.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by: