Skip to content

feat: add GroupValues::lookup - #27664

Open
rkrishn7 wants to merge 3 commits into
apache:mainfrom
rkrishn7:group-values-lookup
Open

rkrishn7 wants to merge 3 commits into
apache:mainfrom
rkrishn7:group-values-lookup

Conversation

@rkrishn7

@rkrishn7 rkrishn7 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

See #27498 and the discussion in #27499. This replaces #27499 with a smaller change: lookup shares each implementation's probe code with intern, so only the no-insert branches are new.

What changes are included in this PR?

  • Adds GroupValues::lookup, which works like intern but never stores a new key. A row whose key is not stored gets MISSING_GROUP.
  • Adds GroupValues::supports_lookup, like supports_values_preserving. By default lookup returns a not-implemented error and supports_lookup returns false, so an implementation can opt out.
  • Each hash-based implementation moves the body of intern into a private probe::<const INSERT: bool>, which both intern and lookup call. The flag is a const generic, so intern has no extra per-row branch.
    • Implemented for GroupValuesPrimitive, GroupValuesBoolean, GroupValuesBytes, GroupValuesBytesView, GroupValuesRows and GroupValuesColumn.
    • ArrowBytesMap and ArrowBytesViewMap get the same treatment and a public find, which backs the bytes implementations.
  • GroupValuesClustered has no hash table, so it does not support lookup.

What is the testing strategy for this PR?

Assertions in existing tests check that lookup returns the same ids intern assigned, returns MISSING_GROUP for missing keys, and leaves len() unchanged. This includes lookups after emit and clear_shrink. The tests also pass with force_hash_collisions.

Are there any user-facing changes?

No changes to query behavior. New public API, with no breaking changes:

  • GroupValues::lookup and GroupValues::supports_lookup, with defaults
  • MISSING_GROUP in aggregates::group_values
  • ArrowBytesMap::find and ArrowBytesViewMap::find in datafusion-physical-expr-common

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate labels Nov 22, 2026

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rkrishn7 -- this looks much better to me -- see also #27499 (comment)

impl GroupValues for GroupValuesRows {
fn intern(&mut self, cols: &[ArrayRef], groups: &mut Vec<usize>) -> Result<()> {
/// [`GroupValues::intern`] if `INSERT`, else [`GroupValues::lookup`].
fn probe<const INSERT: bool>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah -- this looks good to me

@rkrishn7 rkrishn7 changed the title [WIP] feat: add GroupValues::lookup feat: add GroupValues::lookup Nov 23, 2026
@rkrishn7
rkrishn7 marked this pull request as ready for review November 23, 2026 20:14
@rkrishn7

Copy link
Copy Markdown
Contributor Author

run benchmark multi_group_by dictionary_group_values ordered_group_values arrow_bytes_map clickbench_partitioned

@adriangbot

Copy link
Copy Markdown

@rkrishn7

Copy link
Copy Markdown
Contributor Author

Ah could we please trigger benchmarks for multi_group_by dictionary_group_values ordered_group_values arrow_bytes_map clickbench_partitioned. Those should be relevant ones for this work.

I'm also running some local microbenchmarks that cover more GroupValues implementations like GroupValuesPrimitive and GroupValuesPrimitive. I'll post numbers here. If desired, can open a PR for that as a follow-up.

cc @jayzhan211

@rkrishn7

Copy link
Copy Markdown
Contributor Author

@jayzhan211 re: benchmarks, I had Claude run some local benchmarks against main for each implementation and didn't see any regressions.

Each case measures intern over 8 batches of 8192 rows into a fresh GroupValues, at high cardinality (all inserts) and low cardinality (1024 keys, mostly hits). Can view the source here

Benchmark main (µs) PR (µs) PR vs main main vs main
boolean (with nulls) 72.7 72.5 −0.3% −0.5%
bytes, high card 1249.9 1252.6 +0.2% +1.4%
bytes, low card 249.4 251.3 +0.8% −0.7%
bytes long, high card 1242.6 1243.4 +0.1% +1.3%
bytes long, low card 341.4 341.0 −0.1% +0.5%
bytes_view, high card 945.4 938.1 −0.8% +2.2%
bytes_view, low card 179.7 179.7 0.0% +0.1%
bytes_view long, high card 1355.4 1355.1 0.0% +0.5%
bytes_view long, low card 449.7 446.4 −0.7% −0.9%
column streaming, high card 1849.6 1827.8 −1.2% −0.1%
column streaming, low card 849.5 817.9 −3.7% −0.8%
column vectorized, high card 1223.0 1236.1 +1.1% +0.7%
column vectorized, low card 664.8 663.7 −0.2% +1.0%
primitive, high card 779.0 748.6 −3.9% −3.2%
primitive, low card 101.5 102.1 +0.6% +0.3%
rows, high card 1506.6 1513.2 +0.4% +1.1%
rows, low card 703.6 700.9 −0.4% −0.1%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lookup-only GroupValues::find

3 participants