Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Added support for Decimal in build_compare (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
GPSnoopy committed May 21, 2022
1 parent eda7d77 commit a10db3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/array/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result<DynComparato
| (Duration(Nanosecond), Duration(Nanosecond)) => compare_primitives::<i64>(left, right),
(Float32, Float32) => compare_f32(left, right),
(Float64, Float64) => compare_f64(left, right),
(Decimal(_, _), Decimal(_, _)) => compare_primitives::<i128>(left, right),
(Utf8, Utf8) => compare_string::<i32>(left, right),
(LargeUtf8, LargeUtf8) => compare_string::<i64>(left, right),
(Binary, Binary) => compare_binary::<i32>(left, right),
Expand Down
14 changes: 14 additions & 0 deletions tests/it/array/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::cmp::Ordering;

use arrow2::array::ord::build_compare;
use arrow2::array::*;
use arrow2::datatypes::DataType;
use arrow2::error::Result;

#[test]
Expand Down Expand Up @@ -67,6 +68,19 @@ fn f64_zeros() -> Result<()> {
Ok(())
}

#[test]
fn decimal() -> Result<()> {
let array = Int128Array::from_slice(&[1, 2]).to(DataType::Decimal(38, 0));

let cmp = build_compare(&array, &array)?;

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

Ok(())
}

#[test]
fn dict_utf8() -> Result<()> {
let data = vec!["a", "b", "c", "a", "a", "c", "c"];
Expand Down

0 comments on commit a10db3a

Please sign in to comment.