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

Fix comparison of dictionaries with different values arrays (#332) #333

Merged
merged 1 commit into from
May 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions arrow/src/array/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
let right_keys = right.keys_array();

let left_values = StringArray::from(left.values().data().clone());
let right_values = StringArray::from(left.values().data().clone());
let right_values = StringArray::from(right.values().data().clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the copypasta

Copy link
Contributor

Choose a reason for hiding this comment

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

image

🤦


Box::new(move |i: usize, j: usize| {
let key_left = left_keys.value(i).to_usize().unwrap();
Expand Down Expand Up @@ -222,15 +222,15 @@ pub fn build_compare<'a>(left: &'a Array, right: &'a Array) -> Result<DynCompara
return Err(ArrowError::InvalidArgumentError(format!(
"Dictionaries do not support keys of type {:?}",
lhs
)))
)));
}
}
}
(lhs, _) => {
return Err(ArrowError::InvalidArgumentError(format!(
"The data type type {:?} has no natural order",
lhs
)))
)));
}
})
}
Expand Down Expand Up @@ -307,4 +307,19 @@ pub mod tests {
assert_eq!(Ordering::Greater, (cmp)(2, 3));
Ok(())
}

#[test]
fn test_multiple_dict() -> Result<()> {
let d1 = vec!["a", "b", "c", "d"];
let a1 = DictionaryArray::<Int16Type>::from_iter(d1.into_iter());
let d2 = vec!["e", "f", "g", "a"];
let a2 = DictionaryArray::<Int16Type>::from_iter(d2.into_iter());

let cmp = build_compare(&a1, &a2)?;

assert_eq!(Ordering::Less, (cmp)(0, 0));
assert_eq!(Ordering::Equal, (cmp)(0, 3));
assert_eq!(Ordering::Greater, (cmp)(1, 3));
Ok(())
}
}