Skip to content

Commit

Permalink
Sort by float lists (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
medwards authored and alamb committed Jun 8, 2021
1 parent e3d6792 commit 3bc7f80
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions arrow/src/compute/kernels/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ pub fn sort_to_indices(
DataType::UInt64 => {
sort_list::<i32, UInt64Type>(values, v, n, &options, limit)
}
DataType::Float32 => {
sort_list::<i32, Float32Type>(values, v, n, &options, limit)
}
DataType::Float64 => {
sort_list::<i32, Float64Type>(values, v, n, &options, limit)
}
t => Err(ArrowError::ComputeError(format!(
"Sort not supported for list type {:?}",
t
Expand All @@ -294,6 +300,12 @@ pub fn sort_to_indices(
DataType::UInt64 => {
sort_list::<i64, UInt64Type>(values, v, n, &options, limit)
}
DataType::Float32 => {
sort_list::<i64, Float32Type>(values, v, n, &options, limit)
}
DataType::Float64 => {
sort_list::<i64, Float64Type>(values, v, n, &options, limit)
}
t => Err(ArrowError::ComputeError(format!(
"Sort not supported for list type {:?}",
t
Expand All @@ -314,6 +326,12 @@ pub fn sort_to_indices(
DataType::UInt64 => {
sort_list::<i32, UInt64Type>(values, v, n, &options, limit)
}
DataType::Float32 => {
sort_list::<i32, Float32Type>(values, v, n, &options, limit)
}
DataType::Float64 => {
sort_list::<i32, Float64Type>(values, v, n, &options, limit)
}
t => Err(ArrowError::ComputeError(format!(
"Sort not supported for list type {:?}",
t
Expand Down Expand Up @@ -2154,6 +2172,52 @@ mod tests {
Some(1),
);

test_sort_list_arrays::<Float32Type>(
vec![
Some(vec![Some(1.0), Some(0.0)]),
Some(vec![Some(4.0), Some(3.0), Some(2.0), Some(1.0)]),
Some(vec![Some(2.0), Some(3.0), Some(4.0)]),
Some(vec![Some(3.0), Some(3.0), Some(3.0), Some(3.0)]),
Some(vec![Some(1.0), Some(1.0)]),
],
Some(SortOptions {
descending: false,
nulls_first: false,
}),
None,
vec![
Some(vec![Some(1.0), Some(0.0)]),
Some(vec![Some(1.0), Some(1.0)]),
Some(vec![Some(2.0), Some(3.0), Some(4.0)]),
Some(vec![Some(3.0), Some(3.0), Some(3.0), Some(3.0)]),
Some(vec![Some(4.0), Some(3.0), Some(2.0), Some(1.0)]),
],
None,
);

test_sort_list_arrays::<Float64Type>(
vec![
Some(vec![Some(1.0), Some(0.0)]),
Some(vec![Some(4.0), Some(3.0), Some(2.0), Some(1.0)]),
Some(vec![Some(2.0), Some(3.0), Some(4.0)]),
Some(vec![Some(3.0), Some(3.0), Some(3.0), Some(3.0)]),
Some(vec![Some(1.0), Some(1.0)]),
],
Some(SortOptions {
descending: false,
nulls_first: false,
}),
None,
vec![
Some(vec![Some(1.0), Some(0.0)]),
Some(vec![Some(1.0), Some(1.0)]),
Some(vec![Some(2.0), Some(3.0), Some(4.0)]),
Some(vec![Some(3.0), Some(3.0), Some(3.0), Some(3.0)]),
Some(vec![Some(4.0), Some(3.0), Some(2.0), Some(1.0)]),
],
None,
);

test_sort_list_arrays::<Int32Type>(
vec![
Some(vec![Some(1), Some(0)]),
Expand Down

0 comments on commit 3bc7f80

Please sign in to comment.