apache / apache/arrow-rs

Add option to sort by dictionary keys in sort kernels

Open
#980 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
3.6k
Forks
1.3k
Avg merge
2d 18h
Merged PRs (30d)
169

Description

**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**

There are two use cases for this feature:

- Some storage providers or engines are able to guarantee that dictionary keys are already sorted and so sorting could be more efficient by using the keys instead of looking up corresponding strings.
- For the PARTITION BY part of window functions the data does not have to be sorted by the strings, sorting by the keys also ensures a partitioning

**Describe the solution you'd like**

Add a flag `assume_sorted_dictionary` to `SortOptions`. In `sort_to_indices` this flags gets used in the branch for dictionary types and if it is set we sort the keys as a primitive array. The same distinction also needs to be implemented in `build_compare` for the `lexsort_to_indices` kernel.

**Additional context**
Once this is implemented, the window function logic in DataFusion could be adjusted to take advantage of it.

Contributor guide

Open the contributing guide

Research direction

Start by reading SortOptions and the sort_to_indices and build_compare entry points, focusing on their dictionary-type handling. Implement the assume_sorted_dictionary behavior for both sorting paths and verify that dictionary keys determine ordering when the option is enabled while existing behavior remains unchanged otherwise.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.