From 53d06c4c2f4c43f602d9070005ac2243ceb77663 Mon Sep 17 00:00:00 2001 From: Tanguy Fautre Date: Fri, 20 May 2022 22:08:28 +0100 Subject: [PATCH 1/4] Add support for Decimal in build_compare(). --- src/array/ord.rs | 1 + tests/it/array/ord.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/array/ord.rs b/src/array/ord.rs index 614f47f5839..386c44b0a48 100644 --- a/src/array/ord.rs +++ b/src/array/ord.rs @@ -211,6 +211,7 @@ pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result compare_primitives::(left, right), (Float32, Float32) => compare_f32(left, right), (Float64, Float64) => compare_f64(left, right), + (Decimal(_,_), Decimal(_,_)) => compare_primitives::(left, right), (Utf8, Utf8) => compare_string::(left, right), (LargeUtf8, LargeUtf8) => compare_string::(left, right), (Binary, Binary) => compare_binary::(left, right), diff --git a/tests/it/array/ord.rs b/tests/it/array/ord.rs index cf2723436d0..25160d325eb 100644 --- a/tests/it/array/ord.rs +++ b/tests/it/array/ord.rs @@ -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] @@ -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, 2)); + + Ok(()) +} + #[test] fn dict_utf8() -> Result<()> { let data = vec!["a", "b", "c", "a", "a", "c", "c"]; From 7e68dbcedfce71a8ac5dddb6b036baa27464c831 Mon Sep 17 00:00:00 2001 From: Tanguy Fautre Date: Fri, 20 May 2022 22:17:14 +0100 Subject: [PATCH 2/4] Tab to spaces. --- src/array/ord.rs | 2 +- tests/it/array/ord.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/array/ord.rs b/src/array/ord.rs index 386c44b0a48..00f84127219 100644 --- a/src/array/ord.rs +++ b/src/array/ord.rs @@ -211,7 +211,7 @@ pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result compare_primitives::(left, right), (Float32, Float32) => compare_f32(left, right), (Float64, Float64) => compare_f64(left, right), - (Decimal(_,_), Decimal(_,_)) => compare_primitives::(left, right), + (Decimal(_,_), Decimal(_,_)) => compare_primitives::(left, right), (Utf8, Utf8) => compare_string::(left, right), (LargeUtf8, LargeUtf8) => compare_string::(left, right), (Binary, Binary) => compare_binary::(left, right), diff --git a/tests/it/array/ord.rs b/tests/it/array/ord.rs index 25160d325eb..6f2f366d795 100644 --- a/tests/it/array/ord.rs +++ b/tests/it/array/ord.rs @@ -70,14 +70,14 @@ fn f64_zeros() -> Result<()> { #[test] fn decimal() -> Result<()> { - let array = Int128Array::from_slice(&[1, 2]).to(DataType::Decimal(38, 0)); - - let cmp = build_compare(&array, &array)?; + 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, 2)); - + assert_eq!(Ordering::Equal, (cmp)(1, 1)); + assert_eq!(Ordering::Greater, (cmp)(1, 2)); + Ok(()) } From 94d3a718d8b36b69552efa6776645f51500d0498 Mon Sep 17 00:00:00 2001 From: Tanguy Fautre Date: Fri, 20 May 2022 22:18:52 +0100 Subject: [PATCH 3/4] Fix test. --- tests/it/array/ord.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/it/array/ord.rs b/tests/it/array/ord.rs index 6f2f366d795..055f5f9e2c8 100644 --- a/tests/it/array/ord.rs +++ b/tests/it/array/ord.rs @@ -76,7 +76,7 @@ fn decimal() -> Result<()> { assert_eq!(Ordering::Less, (cmp)(0, 1)); assert_eq!(Ordering::Equal, (cmp)(1, 1)); - assert_eq!(Ordering::Greater, (cmp)(1, 2)); + assert_eq!(Ordering::Greater, (cmp)(1, 0)); Ok(()) } From e6307b5acbd60cb59702eeca21f975c70dc6fb81 Mon Sep 17 00:00:00 2001 From: Tanguy Fautre Date: Sat, 21 May 2022 09:04:24 +0100 Subject: [PATCH 4/4] Cargo fmt. --- src/array/ord.rs | 2 +- tests/it/array/ord.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/array/ord.rs b/src/array/ord.rs index 00f84127219..3bb02ba3e72 100644 --- a/src/array/ord.rs +++ b/src/array/ord.rs @@ -211,7 +211,7 @@ pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result compare_primitives::(left, right), (Float32, Float32) => compare_f32(left, right), (Float64, Float64) => compare_f64(left, right), - (Decimal(_,_), Decimal(_,_)) => compare_primitives::(left, right), + (Decimal(_, _), Decimal(_, _)) => compare_primitives::(left, right), (Utf8, Utf8) => compare_string::(left, right), (LargeUtf8, LargeUtf8) => compare_string::(left, right), (Binary, Binary) => compare_binary::(left, right), diff --git a/tests/it/array/ord.rs b/tests/it/array/ord.rs index 055f5f9e2c8..9f5a07ed83b 100644 --- a/tests/it/array/ord.rs +++ b/tests/it/array/ord.rs @@ -71,13 +71,13 @@ fn f64_zeros() -> Result<()> { #[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(()) }