Skip to content

fix: compact FIRST_VALUE scalars during merge - #26743

Merged
alamb merged 4 commits into
apache:mainfrom
lakehq:first-value-compact
Oct 27, 2026
Merged

alamb merged 4 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

@alamb
alamb marked this pull request as draft October 26, 2026 13:02
@alamb

alamb commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Marking as draft as it is waiting on the contributor to add some testing

I also added it to the list on

so we don't forget

@shehabgamin

Copy link
Copy Markdown
Contributor Author

Thanks @shehabgamin and @kumarUjjawal

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

Will do!

@shehabgamin

Copy link
Copy Markdown
Contributor Author

Marking as draft as it is waiting on the contributor to add some testing

@alamb Done!

@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Oct 27, 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.

Thank you @shehabgamin and @kumarUjjawal

@alamb
alamb marked this pull request as ready for review October 27, 2026 09:22
@alamb
alamb added this pull request to the merge queue Oct 27, 2026
Merged via the queue into apache:main with commit 6f1436f Oct 27, 2026
45 checks passed
@alamb
alamb deleted the first-value-compact branch October 27, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt) v56.0.0

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