feat(bindings): spanUnion(span | spanset) → spanset aggregate#53
Closed
estebanzimanyi wants to merge 1 commit intofeat/aggregate-fn-tand-tor-tmin-tmax-tsumfrom
Closed
feat(bindings): spanUnion(span | spanset) → spanset aggregate#53estebanzimanyi wants to merge 1 commit intofeat/aggregate-fn-tand-tor-tmin-tmax-tsumfrom
estebanzimanyi wants to merge 1 commit intofeat/aggregate-fn-tand-tor-tmin-tmax-tsumfrom
Conversation
Adds spanUnion aggregate that merges a column of spans (or spansets)
into a single canonical spanset. 10 overloads:
spanUnion(<span>) -> <spanset> for {int, bigint, float, date, tstz}span
spanUnion(<spanset>) -> <spanset> same 5 types
Closes the architectural gap documented in the parity manifest at
test/sql/parity/015_span_aggfuncs.test (PR #21).
Implementation: new SpansetUnionState holds a heap-allocated
SpanSet*. Same destructor pattern as the skiplist-backed aggregates.
Operation copies the input blob, calls span_union_transfn or
spanset_union_transfn, and reassigns state.spanset to the returned
pointer (the transfn may return a new spanset and free the old
state when it grows). Combine merges via spanset_union_transfn
on (target, source). Finalize calls spanset_union_finalfn which
compacts and frees the state — null state.spanset after to avoid
double-free.
The transfn dispatch is templated on a bool INPUT_IS_SPANSET so
the same SpanUnionFunction handles both Span and SpanSet inputs.
Verified for distinct / overlapping / adjacent spans, nested
spansets, floatspan / tstzspan, and NULL handling (mid-run + all-
NULL → returns NULL).
This was referenced Apr 29, 2026
Member
Author
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
Adds `spanUnion` aggregate — merges a column of spans (or spansets) into a single canonical spanset. 10 overloads:
Closes the architectural gap documented in the parity manifest at `test/sql/parity/015_span_aggfuncs.test` (PR #21).
```sql
SELECT spanUnion(s) FROM (VALUES (intspan '[1, 5)'), (intspan '[3, 8)')) tt(s);
-- {[1, 8)} -- overlap merged
SELECT spanUnion(s) FROM (VALUES (intspan '[1, 3)'), (intspan '[3, 5)')) tt(s);
-- {[1, 5)} -- adjacent merged
SELECT spanUnion(s) FROM (VALUES (intspan '[1, 5)'), (intspan '[10, 12)')) tt(s);
-- {[1, 5), [10, 12)} -- disjoint preserved
```
Implementation
New `SpansetUnionState` holds a heap-allocated `SpanSet *`. Same destructor pattern as the skiplist-backed aggregates (PR #50, PR #52).
The transfn dispatch is templated on `bool INPUT_IS_SPANSET` so the same `SpanUnionFunction` handles both Span and SpanSet inputs.
Stacked on
Test plan