viirya commented on code in PR #2680:
URL: https://github.com/apache/arrow-rs/pull/2680#discussion_r966743659
##########
arrow/src/compute/kernels/sort.rs:
##########
@@ -311,41 +312,58 @@ pub fn sort_to_indices(
)));
}
},
- DataType::Dictionary(key_type, value_type)
- if *value_type.as_ref() == DataType::Utf8 =>
- {
- match key_type.as_ref() {
- DataType::Int8 => {
- sort_string_dictionary::<Int8Type>(values, v, n, &options,
limit)
- }
- DataType::Int16 => {
- sort_string_dictionary::<Int16Type>(values, v, n,
&options, limit)
- }
- DataType::Int32 => {
- sort_string_dictionary::<Int32Type>(values, v, n,
&options, limit)
- }
- DataType::Int64 => {
- sort_string_dictionary::<Int64Type>(values, v, n,
&options, limit)
- }
- DataType::UInt8 => {
- sort_string_dictionary::<UInt8Type>(values, v, n,
&options, limit)
- }
- DataType::UInt16 => {
- sort_string_dictionary::<UInt16Type>(values, v, n,
&options, limit)
- }
- DataType::UInt32 => {
- sort_string_dictionary::<UInt32Type>(values, v, n,
&options, limit)
- }
- DataType::UInt64 => {
- sort_string_dictionary::<UInt64Type>(values, v, n,
&options, limit)
- }
- t => {
- return Err(ArrowError::ComputeError(format!(
- "Sort not supported for dictionary key type {:?}",
- t
- )));
- }
- }
+ DataType::Dictionary(_, _) => {
+ downcast_dictionary_array!(
+ values => match values.values().data_type() {
+ DataType::Int8 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices, v, n, &options, limit, cmp)
+ },
+ DataType::Int16 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices, v, n, &options, limit, cmp)
+ },
+ DataType::Int32 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices, v, n, &options, limit, cmp)
+ },
+ DataType::Int64 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices,v, n, &options, limit, cmp)
+ },
+ DataType::UInt8 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices,v, n, &options, limit, cmp)
+ },
+ DataType::UInt16 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices,v, n, &options, limit, cmp)
+ },
+ DataType::UInt32 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices,v, n, &options, limit, cmp)
+ },
+ DataType::UInt64 => {
+ let dict_values = values.values();
+ let sorted_value_indices =
sort_to_indices(dict_values, Some(SortOptions::default()), None)?;
+ sort_primitive_dictionary::<_, _>(values,
&sorted_value_indices, v, n, &options, limit, cmp)
+ },
+ DataType::Utf8 => sort_string_dictionary::<_>(values, v,
n, &options, limit),
Review Comment:
I think `sort_string_dictionary` also can be optimized by this trick to sort
on values first. I will leave it to a follow-up PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]