Skip to content

Fix NPE of approx_most_frequent and approx_count_distinct on empty input - #19168

Open
alpass163 wants to merge 2 commits into
apache:masterfrom
alpass163:cyb/fix_approx_most_frequent
Open

alpass163 wants to merge 2 commits into
apache:masterfrom
alpass163:cyb/fix_approx_most_frequent

Conversation

@alpass163

Copy link
Copy Markdown
Contributor

Fix NPE of approx_most_frequent and approx_count_distinct on empty input

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

One correctness regression remains in the grouped BLOB aggregation path; please address the inline comment.

Comment on lines +47 to +49
if (spaceSaving == null || spaceSaving.isEmpty()) {
columnBuilder.appendNull();
return;

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.

[P2] Handle empty BLOB groups in the overridden final evaluator

Please also add the null/empty-state guard to BlobGroupedApproxMostFrequentAccumulator.evaluateFinal(). For a group whose BLOB values are all NULL, this inherited evaluateIntermediate() now emits NULL, and BinaryGroupedApproxMostFrequentAccumulator.addIntermediate() skips it, leaving the final group's state uninitialized. The BLOB-specific evaluateFinal() overrides the guarded base implementation and still calls state.getSpaceSavings().get(groupId).getBuckets() unconditionally, so a PARTIAL -> FINAL aggregation now throws an NPE. I reproduced this with the parent and PR accumulator sources: the parent returns {}, whereas this revision throws. Please add a grouped BLOB regression test covering an all-NULL group through partial/final aggregation, including alongside a nonempty group.

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.

2 participants