Distinguish nils in firstBuffer #3030
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 anil
because the buffer is empty and anil
because the value in that column of the first row isnil
.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 benil
, it ends up getting overwritten by the1
in the second row. Because the second value is notnil
,Update
skips it. As a result, we end up with a row{1, 1}
that matches neither of the original rows and evaluates toTRUE
when grouped byc0 = c1
, even though the original rows evaluate toNULL
.This isn't an issue when the rows are
(NULL, 1), (NULL, 1)
or(1, NULL), (1, NULL)
because thenil
value remains anil
value whenUpdate
is called on the second row.I fixed this by adding a
writtenNil
flag tofirstBuffer
to indicate that thenil
value is meant to be there and should not be overwritten.