From 8fac8fcdcbb93a2cd6960d6beefab4b23843e873 Mon Sep 17 00:00:00 2001 From: Max Burke Date: Thu, 20 Oct 2022 12:50:17 -0700 Subject: [PATCH 1/2] implement ord for FixedSizeBinary types --- arrow/src/array/ord.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arrow/src/array/ord.rs b/arrow/src/array/ord.rs index 3fc62f807bef..1c062f46dfab 100644 --- a/arrow/src/array/ord.rs +++ b/arrow/src/array/ord.rs @@ -295,6 +295,14 @@ pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result { + let left: FixedSizeBinaryArray = + FixedSizeBinaryArray::from(left.data().clone()); + let right: FixedSizeBinaryArray = + FixedSizeBinaryArray::from(right.data().clone()); + + Box::new(move |i, j| left.value(i).cmp(right.value(j))) + } (lhs, _) => { return Err(ArrowError::InvalidArgumentError(format!( "The data type type {:?} has no natural order", From edc745e568cbbfe3916471a1a8d20b06ae561d37 Mon Sep 17 00:00:00 2001 From: Max Burke Date: Thu, 20 Oct 2022 13:22:06 -0700 Subject: [PATCH 2/2] add ord test --- arrow/src/array/ord.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arrow/src/array/ord.rs b/arrow/src/array/ord.rs index 1c062f46dfab..305d41cc0167 100644 --- a/arrow/src/array/ord.rs +++ b/arrow/src/array/ord.rs @@ -315,10 +315,34 @@ pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result Result<()> { + let items = vec![vec![1u8], vec![2u8]]; + let array = FixedSizeBinaryArray::try_from_iter(items.into_iter()).unwrap(); + + let cmp = build_compare(&array, &array)?; + + assert_eq!(Ordering::Less, (cmp)(0, 1)); + Ok(()) + } + + #[test] + fn test_fixed_size_binary_fixed_size_binary() -> Result<()> { + let items = vec![vec![1u8]]; + let array1 = FixedSizeBinaryArray::try_from_iter(items.into_iter()).unwrap(); + let items = vec![vec![2u8]]; + let array2 = FixedSizeBinaryArray::try_from_iter(items.into_iter()).unwrap(); + + let cmp = build_compare(&array1, &array2)?; + + assert_eq!(Ordering::Less, (cmp)(0, 0)); + Ok(()) + } + #[test] fn test_i32() -> Result<()> { let array = Int32Array::from(vec![1, 2]);