Preserve NULLs in array_agg pushdown - #340
Open
fallintoplace wants to merge 1 commit into
Open
Conversation
theory
requested changes
Aug 6, 2026
theory
left a comment
Collaborator
There was a problem hiding this comment.
Good find. Please add a changelog item and write a descriptive commit 72/50 message in a single commit.
| * length(arr)-n) */ | ||
| CF_ARRAY_SORT_DESC, /* array_sort(arr,desc) → | ||
| * arrayReverseSort/arraySort */ | ||
| CF_ARRAY_AGG, |
Comment on lines
+1219
to
+1221
| if ((agg->aggfnoid == F_STRING_AGG_TEXT_TEXT || | ||
| agg->aggfnoid == F_ARRAY_AGG_ANYNONARRAY) && | ||
| agg->aggorder != NIL) { |
Collaborator
There was a problem hiding this comment.
Need test rejecting use of ORDER with F_ARRAY_AGG_ANYNONARRAY
| EXPLAIN (VERBOSE, COSTS OFF) SELECT array_agg(v) FROM agg_bin.null_agg; | ||
| SELECT array_agg(v) FROM agg_bin.null_agg; | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT array_agg(v) FROM agg_http.null_agg; | ||
| SELECT array_agg(v) FROM agg_http.null_agg; |
Collaborator
There was a problem hiding this comment.
This is useful but we also need tests to cover all of the variants in deparseArrayAggref(): filter, distinct, and nullable.
fallintoplace
force-pushed
the
fix/array-agg-null-preservation
branch
from
August 6, 2026 20:44
3a33223 to
f4c4699
Compare
Wrap nullable inputs in tuples before passing them to ClickHouse groupArray so NULL elements are preserved. Keep ordered array_agg local because groupArray does not preserve PostgreSQL ordering. Add regression coverage for nullable, FILTER, DISTINCT, and ORDER BY array_agg variants.
fallintoplace
force-pushed
the
fix/array-agg-null-preservation
branch
from
August 6, 2026 20:45
f4c4699 to
197602a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ClickHouse groupArray() skips NULL values, while PostgreSQL array_agg() preserves them. Wrap nullable inputs in a tuple before groupArray and unwrap them with arrayMap so NULL elements survive the pushdown.
Non-nullable array_agg() plans keep their existing SQL. Ordered array_agg() stays local because the wrapper does not preserve ordering.
Testing