feat(bindings): aggregate function infrastructure — extent(span) for all 5 span types#47
Merged
Merged
Conversation
…n types Lands the first MobilityDuck AggregateFunction registration: extent(span) that aggregates a column of spans into the bounding span of all values. Registers a single AggregateFunctionSet "extent" with five overloads (intspan, bigintspan, floatspan, datespan, tstzspan). Implementation pattern (in src/temporal/span_aggregates.cpp): - SpanExtentState holds an inline Span + bool isset. The MEOS Span is a fixed-size struct so the state is POD and trivially serialisable. - SpanExtentFunction provides Initialize / Operation / ConstantOperation / Combine / Finalize via DuckDB's UnaryAggregate template helper. - Operation and Combine bridge to MEOS span_extent_transfn, which expands state's bounds in place when state is non-null and otherwise returns a fresh palloc'd copy. Since our state is inline we just memcpy the Span on first input. - Finalize uses finalize_data.ReturnString(string_t(&state.span, sizeof(Span))) to emit the result blob. This pattern extends naturally to: - extent(spanset) via spanset_extent_transfn - extent(set) via set_extent_transfn - extent(tnumber) via tnumber_extent_transfn (returns TBox state) - tcount / tand / tor / tmin / tmax / tsum via skiplist-backed states - spanUnion(span) via spanset_union_transfn This first PR establishes the infrastructure; follow-up PRs land each of the listed aggregates against the same scaffolding.
This was referenced Apr 29, 2026
3 tasks
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
Lands the first MobilityDuck AggregateFunction registration. Adds `extent(span)` that aggregates a column of spans into the bounding span over all values, for the 5 span types: `intspan`, `bigintspan`, `floatspan`, `datespan`, `tstzspan`.
```sql
SELECT extent(s) FROM (VALUES (intspan '[1, 5)'), (intspan '[3, 8)'), (intspan '[10, 12)')) t(s);
-- [1, 12)
SELECT extent(s) FROM (VALUES (datespan '[2000-01-01, 2000-01-05]'), (datespan '[2000-01-03, 2000-01-10]')) t(s);
-- [2000-01-01, 2000-01-11)
```
Implementation pattern
New module: `src/temporal/span_aggregates.cpp` + `src/include/temporal/span_aggregates.hpp`.
The same scaffolding extends naturally to the rest of the aggregate surface (architectural blocker for parity tests #21, #40, parts of #25):
This PR establishes the bridging pattern; follow-up PRs land each of the above on the same scaffolding.
Test plan