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

Use DictionaryArray's iterator in compare_dict_op #1330

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 16 additions & 17 deletions arrow/src/compute/kernels/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2213,27 +2213,26 @@ macro_rules! compare_dict_op {
.to_string(),
));
}
let left_values = $left.values().as_any().downcast_ref::<$value_ty>().unwrap();
let right_values = $right

let left_iter = $left
Copy link
Contributor

Choose a reason for hiding this comment

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

This sure looks much nicer 👍

.values()
.as_any()
.downcast_ref::<$value_ty>()
.unwrap();
.unwrap()
.take_iter($left.keys_iter());

let result = $left
.keys()
.iter()
.zip($right.keys().iter())
.map(|(left_key, right_key)| {
if let (Some(left_k), Some(right_k)) = (left_key, right_key) {
let left_key = left_k.to_usize().expect("Dictionary index not usize");
let right_key =
right_k.to_usize().expect("Dictionary index not usize");
unsafe {
let left_value = left_values.value_unchecked(left_key);
let right_value = right_values.value_unchecked(right_key);
Some($op(left_value, right_value))
}
let right_iter = $right
.values()
.as_any()
.downcast_ref::<$value_ty>()
.unwrap()
.take_iter($right.keys_iter());

let result = left_iter
.zip(right_iter)
.map(|(left_value, right_value)| {
if let (Some(left), Some(right)) = (left_value, right_value) {
Some($op(left, right))
} else {
None
}
Expand Down