Skip to content

Clean up InList code to use functions rather than macros#2826

Closed
alamb wants to merge 1 commit intoapache:masterfrom
alamb:alamb/cleanup_in_list
Closed

Clean up InList code to use functions rather than macros#2826
alamb wants to merge 1 commit intoapache:masterfrom
alamb:alamb/cleanup_in_list

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Jul 2, 2022

Which issue does this PR close?

N/A (at the moment)

Rationale for this change

Inspired by @liukun4515 's PR here: #2809 I saw some macro use that could be reduced and may even be faster

What changes are included in this PR?

  1. Remove macro use when checking for set inclusion

Are there any user-facing changes?

No

@github-actions github-actions bot added the physical-expr Changes to the physical-expr crates label Jul 2, 2022
///
/// # Example
/// TODO
fn unary_cmp<I, F>(array: &PrimitiveArray<I>, op: F) -> BooleanArray
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ted-Jiang are there any performance benchmarks that can be run for the InList implementation?

let null_bit_buffer = $left.data().null_buffer().cloned();

let comparison =
(0..$left.len()).map(|i| unsafe { $op($left.value_unchecked(i), $right) });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in general using iterators (rather than value_unchecked()) is faster

Comment on lines +50 to +51
/// Applies an unary and infallible comparison function to a primitive
/// array. This is the fastest way to perform an operation on a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Applies an unary and infallible comparison function to a primitive
/// array. This is the fastest way to perform an operation on a
/// TODO: move to arrow-rs: https://github.com/apache/arrow-rs/issues/1987
///
/// Applies an unary and infallible comparison function to a primitive
/// array. This is the fastest way to perform an operation on a

fn in_list_primitive<T: ArrowPrimitiveType>(
array: &PrimitiveArray<T>,
values: &[<T as ArrowPrimitiveType>::Native],
) -> Result<BooleanArray> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made infallible as it can't fail

) -> BooleanArray {
array
.iter()
.map(|x| x.map(|x| !values.contains(&x)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change now does check each element if it is Null before invoking the closure where the compare_op_scalar! macro does not. However, given that that the closure will do some non trivial string checks, I think first checking for null will likely not slow it down

@alamb
Copy link
Contributor Author

alamb commented Jul 2, 2022

Hmm, something is not correct. Will investigate

@alamb alamb closed this Aug 13, 2022
@alamb
Copy link
Contributor Author

alamb commented Aug 13, 2022

I don't have time / plans to work on this any more

@alamb alamb deleted the alamb/cleanup_in_list branch August 8, 2023 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant