feat(bindings): tAnd / tOr / tagg_min / tagg_max / tagg_sum aggregates#52
Closed
estebanzimanyi wants to merge 1 commit into
Closed
Conversation
Adds 5 more skiplist-backed temporal aggregates on top of the infrastructure landed for tCount: tAnd(tbool) -> tbool per-instant boolean AND tOr(tbool) -> tbool per-instant boolean OR tagg_min(tint) -> tint per-instant minimum tagg_min(tfloat) -> tfloat tagg_max(tint) -> tint per-instant maximum tagg_max(tfloat) -> tfloat tagg_sum(tint) -> tint per-instant sum tagg_sum(tfloat) -> tfloat ttext skipped — text merge needs text_cmp plumbing not yet wired. Implementation factors out the boilerplate from TCountFunction into a templated SkiplistAggFunction<TRANSFN, MERGE_FN, CROSSINGS> functor. Each aggregate is one MakeSkiplistAggregate<...> instantiation. The merge functions used by Combine (datum_and, datum_or, datum_min_int32, datum_max_int32, datum_sum_int32, datum_min_float8, datum_max_float8, datum_sum_float8) are NOT exported from MEOS, so local equivalents are provided. Float8 conversion goes through a union to handle the IEEE 754 bit-pattern in Datum. Naming note: tagg_min / tagg_max / tagg_sum instead of tMin / tMax / tSum because Tmin / Tmax already exist as scalar time-min / time-max accessors on tbox / stbox. DuckDB's catalog is case-insensitive at the name level, so registering an aggregate named tMin would trigger an ALTER path on the existing scalar that CreateAggregateFunctionInfo doesn't implement, and the extension would fail to load.
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 5 more skiplist-backed temporal aggregates on top of the infrastructure landed for `tCount` (PR #50):
ttext skipped — text merge needs `text_cmp` plumbing not yet wired.
```sql
SELECT tagg_min(t) FROM (VALUES (tint '5@2000-01-01'), (tint '3@2000-01-01')) tt(t);
-- {3@2000-01-01 00:00:00+00}
SELECT tAnd(t) FROM (VALUES (tbool 't@2000-01-01'), (tbool 'f@2000-01-01')) tt(t);
-- {f@2000-01-01 00:00:00+00}
```
Implementation
Factors the boilerplate from `TCountFunction` into a templated functor:
```cpp
template <TempTransfn TRANSFN, Datum (*MERGE_FN)(Datum, Datum), bool CROSSINGS>
struct SkiplistAggFunction { ... };
```
Each aggregate is now one `MakeSkiplistAggregate<&meos_transfn, &merge_fn, crossings>(input, output)` instantiation.
The merge functions used by `Combine` (`datum_and`, `datum_or`, `datum_min_int32`, `datum_max_int32`, `datum_sum_int32`, `datum_min_float8`, `datum_max_float8`, `datum_sum_float8`) are not exported from MEOS, so local equivalents are provided in this file. Float8 conversion goes through an aliased union to handle the IEEE 754 bit-pattern stored in `Datum`.
Naming note (`tagg_*` instead of `tMin`/`tMax`/`tSum`)
`Tmin` and `Tmax` are already registered as scalar time-min / time-max accessors on tbox / stbox (`src/temporal/tbox.cpp` line 396, 414, `src/geo/stbox.cpp` line 257, 302). DuckDB's catalog is case-insensitive at the name level, so registering an aggregate named `tMin` would lookup-collide with the existing scalar and trigger an `ALTER` path that `CreateAggregateFunctionInfo` doesn't implement (`GetAlterInfo not implemented for this type`) — extension fails to load.
The `tagg_*` prefix sidesteps the collision. A future cleanup could rename the existing scalars (e.g. to `time_min(tbox)` / `time_max(tbox)`) and reclaim the `tMin` / `tMax` / `tSum` names if MobilityDB-name parity is preferred.
Stacked on
Test plan