This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new f629a2ebe Implement ord for FixedSizeBinary types (#2905)
f629a2ebe is described below

commit f629a2ebe08033e7b78585d82e98c50a4439e7a2
Author: Max Burke <[email protected]>
AuthorDate: Fri Oct 21 12:06:46 2022 -0700

    Implement ord for FixedSizeBinary types (#2905)
    
    * implement ord for FixedSizeBinary types
    
    * add ord test
---
 arrow/src/array/ord.rs | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/arrow/src/array/ord.rs b/arrow/src/array/ord.rs
index 3fc62f807..305d41cc0 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<DynComparato
             let right: Decimal128Array = 
Decimal128Array::from(right.data().clone());
             Box::new(move |i, j| left.value(i).cmp(&right.value(j)))
         }
+        (FixedSizeBinary(_), FixedSizeBinary(_)) => {
+            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",
@@ -307,10 +315,34 @@ pub fn build_compare(left: &dyn Array, right: &dyn Array) 
-> Result<DynComparato
 #[cfg(test)]
 pub mod tests {
     use super::*;
-    use crate::array::{Float64Array, Int32Array};
+    use crate::array::{FixedSizeBinaryArray, Float64Array, Int32Array};
     use crate::error::Result;
     use std::cmp::Ordering;
 
+    #[test]
+    fn test_fixed_size_binary() -> 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]);

Reply via email to