apache / apache/datafusion

Specialized GroupValues Implementation for Ordered Data

Open
#14,574 2 comments 4 reactions 1 assignee Claimed by @QinXi-ai View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Is your feature request related to a problem or challenge?

When processing data that's already sorted by group keys, the current GroupBy implementation only partially utilizes this ordering. While it uses GroupOrdering to emit batches early, it still relies on a HashMap for the GroupValues mapping, which is suboptimal for pre-sorted data.

For pre-sorted data, GroupValues can be optimized by:
1. Replacing the HashMap with a simpler tracking mechanism that only stores:
- The last row from the previous batch
- The count of previously seen groups
2. Using arrow_ord::partition::partition for direct equality comparison between rows, eliminating the need for hashing
3. Enabling earlier row emission: As soon as a new group is detected, the previous group is guaranteed to be complete and can be emitted

Current Behavior:
- Uses GroupOrdering for early batch emission
- Still maintains a HashMap for GroupValues mapping regardless of data ordering

### Describe the solution you'd like

Implement a specialized GroupValues for ordered data that takes full advantage of these optimization opportunities. This should improve performance for the pre-sorted data case while maintaining the existing functionality for unordered data.

Expected Benefits:
- Reduced memory usage (no HashMap needed)
- Fewer operations (equality comparison vs hashing + equality comparison)
- Make GroupOrderingFull obsolete?

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.