Skip to content

fix: compact FIRST_VALUE scalars during merge - #26743

Open
shehabgamin wants to merge 2 commits into
apache:mainfrom
lakehq:first-value-compact
Open

shehabgamin wants to merge 2 commits into
apache:mainfrom
lakehq:first-value-compact

Conversation

@shehabgamin

@shehabgamin shehabgamin commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #26744.

Rationale for this change

DISTINCT ON queries carrying nested payloads can fail with a memory reservation error during aggregate spill/replay because merged FIRST_VALUE states retain backing buffers from larger arrays.

What changes are included in this PR?

Call self.first.compact() after extracting the selected scalar in TrivialFirstValueAccumulator::merge_batch, matching the existing behavior in update_batch.

What is the testing strategy for this PR?

Locally validated against unpatched and patched DataFusion 55.2.0. An accumulator regression check confirms that merging a list state preserves its value and reports the same memory size as updating it directly; it fails before the fix and passes afterward.

The spill workload described in #26744 fails before the fix and returns all 8,192 rows with correct nested payloads afterward, while still exercising spilling.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added the functions Changes to functions implementation label Oct 25, 2026
@shehabgamin
shehabgamin marked this pull request as ready for review October 25, 2026 11:45
Copilot AI balanced review requested due to automatic review settings October 25, 2026 11:45

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@shehabgamin shehabgamin changed the title fix: Compact scalars during merge fix: compact FIRST_VALUE scalars during merge Oct 25, 2026

@kumarUjjawal kumarUjjawal 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.

Thank you @shehabgamin

Looks good 👍

@alamb

alamb commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Thanks @shehabgamin and @kumarUjjawal

Is there any way we can get a .slt / sql end user API repro for this?

@alamb

alamb commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

The reproducer in #26744 (comment) is probably a good start

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

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DISTINCT ON with nested payloads can fail memory reservation after spilling

4 participants