Skip to content

Commit

Permalink
Cleanup decimal sort function (#2908)
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Oct 21, 2022
1 parent 5de555e commit be48377
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions arrow/src/compute/kernels/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit be48377

Please sign in to comment.