diff --git a/src/array/ord.rs b/src/array/ord.rs index 3eb1a98ae53..17dd0bc4653 100644 --- a/src/array/ord.rs +++ b/src/array/ord.rs @@ -7,7 +7,7 @@ use crate::error::{ArrowError, Result}; use crate::{array::*, types::NativeType}; /// Compare the values at two arbitrary indices in two arrays. -pub type DynComparator<'a> = Box Ordering + 'a>; +pub type DynComparator = Box Ordering + Send + Sync>; /// implements comparison using IEEE 754 total ordering for f32 // Original implementation from https://doc.rust-lang.org/std/primitive.f32.html#method.total_cmp @@ -47,66 +47,57 @@ where l.cmp(r) } -fn compare_primitives<'a, T: NativeType + Ord>( - left: &'a dyn Array, - right: &'a dyn Array, -) -> DynComparator<'a> { - let left = left.as_any().downcast_ref::>().unwrap(); - let right = right.as_any().downcast_ref::>().unwrap(); - let left = left.values(); - let right = right.values(); - Box::new(move |i, j| total_cmp(&left[i], &right[j])) +fn compare_primitives(left: &dyn Array, right: &dyn Array) -> DynComparator { + let left = left.as_any().downcast_ref::>().unwrap().clone(); + let right = right.as_any().downcast_ref::>().unwrap().clone(); + Box::new(move |i, j| total_cmp(&left.value(i), &right.value(j))) } -fn compare_boolean<'a>(left: &'a dyn Array, right: &'a dyn Array) -> DynComparator<'a> { - let left = left.as_any().downcast_ref::().unwrap(); - let right = right.as_any().downcast_ref::().unwrap(); +fn compare_boolean(left: &dyn Array, right: &dyn Array) -> DynComparator { + let left = left.as_any().downcast_ref::().unwrap().clone(); + let right = right.as_any().downcast_ref::().unwrap().clone(); Box::new(move |i, j| left.value(i).cmp(&right.value(j))) } -fn compare_f32<'a>(left: &'a dyn Array, right: &'a dyn Array) -> DynComparator<'a> { - let left = left.as_any().downcast_ref::>().unwrap(); +fn compare_f32(left: &dyn Array, right: &dyn Array) -> DynComparator { + let left = left.as_any().downcast_ref::>().unwrap().clone(); let right = right .as_any() .downcast_ref::>() - .unwrap(); - let left = left.values(); - let right = right.values(); - Box::new(move |i, j| total_cmp_f32(&left[i], &right[j])) + .unwrap().clone(); + Box::new(move |i, j| total_cmp_f32(&left.value(i), &right.value(j))) } -fn compare_f64<'a>(left: &'a dyn Array, right: &'a dyn Array) -> DynComparator<'a> { - let left = left.as_any().downcast_ref::>().unwrap(); +fn compare_f64(left: &dyn Array, right: &dyn Array) -> DynComparator { + let left = left.as_any().downcast_ref::>().unwrap().clone(); let right = right .as_any() .downcast_ref::>() - .unwrap(); - let left = left.values(); - let right = right.values(); - Box::new(move |i, j| total_cmp_f64(&left[i], &right[j])) + .unwrap().clone(); + Box::new(move |i, j| total_cmp_f64(&left.value(i), &right.value(j))) } -fn compare_string<'a, O: Offset>(left: &'a dyn Array, right: &'a dyn Array) -> DynComparator<'a> { - let left = left.as_any().downcast_ref::>().unwrap(); - let right = right.as_any().downcast_ref::>().unwrap(); +fn compare_string(left: &dyn Array, right: &dyn Array) -> DynComparator { + let left = left.as_any().downcast_ref::>().unwrap().clone(); + let right = right.as_any().downcast_ref::>().unwrap().clone(); Box::new(move |i, j| left.value(i).cmp(right.value(j))) } -fn compare_binary<'a, O: Offset>(left: &'a dyn Array, right: &'a dyn Array) -> DynComparator<'a> { - let left = left.as_any().downcast_ref::>().unwrap(); - let right = right.as_any().downcast_ref::>().unwrap(); +fn compare_binary(left: &dyn Array, right: &dyn Array) -> DynComparator { + let left = left.as_any().downcast_ref::>().unwrap().clone(); + let right = right.as_any().downcast_ref::>().unwrap().clone(); Box::new(move |i, j| left.value(i).cmp(right.value(j))) } -fn compare_dict<'a, K>( - left: &'a DictionaryArray, - right: &'a DictionaryArray, -) -> Result> +fn compare_dict( + left: &DictionaryArray, + right: &DictionaryArray, +) -> Result where K: DictionaryKey, { - let left_keys = left.keys().values(); - let right_keys = right.keys().values(); + let left_keys = left.keys().values().clone(); + let right_keys = right.keys().values().clone(); let comparator = build_compare(left.values().as_ref(), right.values().as_ref())?; @@ -145,8 +136,7 @@ macro_rules! dyn_dict { /// # Error /// The arrays' [`DataType`] must be equal and the types must have a natural order. // This is a factory of comparisons. -// The lifetime 'a enforces that we cannot use the closure beyond any of the array's lifetime. -pub fn build_compare<'a>(left: &'a dyn Array, right: &'a dyn Array) -> Result> { +pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result { use DataType::*; use IntervalUnit::*; use TimeUnit::*;