You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/10/21 06:43:29 UTC
[arrow-rs] branch master updated: Cleanup decimal sort function (#2908)
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 be4837770 Cleanup decimal sort function (#2908)
be4837770 is described below
commit be483777092cb1007ced0323a1c659c2634b1a5c
Author: Liang-Chi Hsieh <vi...@gmail.com>
AuthorDate: Thu Oct 20 23:43:23 2022 -0700
Cleanup decimal sort function (#2908)
---
arrow/src/compute/kernels/sort.rs | 35 +++--------------------------------
1 file changed, 3 insertions(+), 32 deletions(-)
diff --git a/arrow/src/compute/kernels/sort.rs b/arrow/src/compute/kernels/sort.rs
index 71bc9464e..6720a0c5c 100644
--- a/arrow/src/compute/kernels/sort.rs
+++ b/arrow/src/compute/kernels/sort.rs
@@ -146,7 +146,9 @@ pub fn sort_to_indices(
let (v, n) = partition_validity(values);
Ok(match values.data_type() {
- DataType::Decimal128(_, _) => sort_decimal(values, v, n, cmp, &options, limit),
+ DataType::Decimal128(_, _) => {
+ sort_primitive::<Decimal128Type, _>(values, v, n, cmp, &options, limit)
+ }
DataType::Boolean => sort_boolean(values, v, n, &options, limit),
DataType::Int8 => {
sort_primitive::<Int8Type, _>(values, v, n, cmp, &options, limit)
@@ -474,37 +476,6 @@ fn sort_boolean(
UInt32Array::from(result_data)
}
-/// Sort Decimal array
-fn sort_decimal<F>(
- decimal_values: &ArrayRef,
- value_indices: Vec<u32>,
- null_indices: Vec<u32>,
- cmp: F,
- options: &SortOptions,
- limit: Option<usize>,
-) -> UInt32Array
-where
- F: Fn(i128, i128) -> std::cmp::Ordering,
-{
- // downcast to decimal array
- let decimal_array = decimal_values
- .as_any()
- .downcast_ref::<Decimal128Array>()
- .expect("Unable to downcast to decimal array");
- let valids = value_indices
- .into_iter()
- .map(|index| (index, decimal_array.value(index as usize)))
- .collect::<Vec<(u32, i128)>>();
- sort_primitive_inner(
- decimal_values.len(),
- null_indices,
- cmp,
- options,
- limit,
- valids,
- )
-}
-
/// Sort primitive values
fn sort_primitive<T, F>(
values: &ArrayRef,