Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kernel to quickly compute comparisons on Arrays #1987

Closed
alamb opened this issue Jul 2, 2022 · 1 comment · Fixed by #1991
Closed

Add kernel to quickly compute comparisons on Arrays #1987

alamb opened this issue Jul 2, 2022 · 1 comment · Fixed by #1991
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@alamb
Copy link
Contributor

alamb commented Jul 2, 2022

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
DataFusion (and likely other libraries) often wants to implement its own fast comparison functions

For example, comparing the contents of an array element by element to form an output BooleanArray
https://github.com/apache/arrow-datafusion/blob/7617d78809d4ff5bde31142e0744c70024e40635/datafusion/physical-expr/src/expressions/in_list.rs#L50

the arity::unary is close to what I want: https://docs.rs/arrow/17.0.0/arrow/compute/kernels/arity/index.html but it can not produce a BooleanArray (because BooleanArray is not a PrimitiveArray)

fn in_list_primitive<T: ArrowPrimitiveType>(
    array: &PrimitiveArray<T>,
    values: &[<T as ArrowPrimitiveType>::Native],
) -> Result<BooleanArray> {
    Ok(arity::unary(array, |x| values.contains(&x)))
}

Describe the solution you'd like
I would like a function such as unary_cmp that I could call like:

fn in_list_primitive<T: ArrowPrimitiveType>(
    array: &PrimitiveArray<T>,
    values: &[<T as ArrowPrimitiveType>::Native],
) -> Result<BooleanArray> {
    Ok(arity::unary_cmp(array, |x| values.contains(&x)))
}

There is a proposed implementation: apache/arrow-datafusion#2826

Describe alternatives you've considered

Additional context
Add any other context or screenshots about the feature request here.

@alamb alamb added the enhancement Any new improvement worthy of a entry in the changelog label Jul 2, 2022
@alamb alamb changed the title Expose kernel to quickly compute comparisons of arrays Kernel to quickly compute comparisons of arrays Jul 2, 2022
@alamb alamb added the arrow Changes to the arrow crate label Jul 2, 2022
@viirya viirya mentioned this issue Jul 2, 2022
@viirya
Copy link
Member

viirya commented Jul 2, 2022

Instead of copying unary, seems we can reuse exist compare code like #1991

@alamb alamb changed the title Kernel to quickly compute comparisons of arrays Add kernel to quickly compute comparisons on Arrays Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants