Skip to content

Distinguish nils in firstBuffer #3030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
Merged

Distinguish nils in firstBuffer #3030

merged 2 commits into from
Jun 13, 2025

Conversation

angelamayxie
Copy link
Contributor

@angelamayxie angelamayxie commented Jun 13, 2025

Fixes dolthub/dolt#9035

In AggregationBuffer.firstBuffer , the buffer should not update if the first row has already been written. However, there was no way of distinguishing between a nil because the buffer is empty and a nil because the value in that column of the first row is nil.

When you have two rows (NULL, 1) and (1, NULL), the first row gets written into []firstBuffer.val as {nil, 1}. Because there's no way to tell whether the first value is supposed to be nil, it ends up getting overwritten by the 1 in the second row. Because the second value is not nil, Update skips it. As a result, we end up with a row {1, 1} that matches neither of the original rows and evaluates to TRUE when grouped by c0 = c1, even though the original rows evaluate to NULL.

This isn't an issue when the rows are (NULL, 1), (NULL, 1) or (1, NULL), (1, NULL) because the nil value remains a nil value when Update is called on the second row.

I fixed this by adding a writtenNil flag to firstBuffer to indicate that the nil value is meant to be there and should not be overwritten.

@angelamayxie angelamayxie requested a review from jycor June 13, 2025 17:24
@angelamayxie angelamayxie marked this pull request as ready for review June 13, 2025 17:42
Copy link
Contributor

@jycor jycor left a comment

Choose a reason for hiding this comment

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

Nice catch!
LGTM

@angelamayxie angelamayxie merged commit 4434731 into main Jun 13, 2025
8 checks passed
@angelamayxie angelamayxie deleted the angela/groupby branch June 13, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NULL in GROUP BY column is interpreted as 1
2 participants