Skip to content

Commit

Permalink
fix comparison of dictionaries with different values arrays (#332) (#333
Browse files Browse the repository at this point in the history
) (#357)

Co-authored-by: Raphael Taylor-Davies <[email protected]>
  • Loading branch information
alamb and tustvold authored May 26, 2021
1 parent 6ef14ce commit ceeab6c
Showing 1 changed file with 18 additions and 3 deletions.
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());

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(())
}
}

0 comments on commit ceeab6c

Please sign in to comment.