Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup decimal sort function #2908

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 3 additions & 32 deletions arrow/src/compute/kernels/sort.rs
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