feat(bindings): tAvg(tnumber) and wavg(tnumber, INTERVAL) aggregates#59
Closed
estebanzimanyi wants to merge 2 commits into
Closed
feat(bindings): tAvg(tnumber) and wavg(tnumber, INTERVAL) aggregates#59estebanzimanyi wants to merge 2 commits into
estebanzimanyi wants to merge 2 commits into
Conversation
Adds the temporal-average aggregate over tint and tfloat:
tAvg(tint) -> tfloat
tAvg(tfloat) -> tfloat
State holds a SkipList of {sum, count} pairs (MEOS double2 layout).
Operation calls tnumber_tavg_transfn. Combine merges two states via
temporal_skiplist_splice with mduck_datum_sum_double2 as merge fn —
this is a local replica of MEOS's internal datum_sum_double2 since
that symbol is not exported by MEOS public headers. Finalize calls
tnumber_tavg_finalfn which computes per-instant sum/count and frees
the skiplist; we null state.skiplist after to avoid double-free in
the destructor.
Windowed time-weighted average — companion to wmin/wmax/wsum window aggregates. Uses tnumber_wavg_transfn for accumulation and reuses the tAvg machinery (datum_sum_double2 merge function and tnumber_tavg_finalfn) for combine and finalize. WavgFunction is a separate functor from the existing WindowAggFunction template because wavg's finalfn is tnumber_tavg_finalfn rather than the generic temporal_tagg_finalfn, and its merge fn is fixed to mduck_datum_sum_double2.
Member
Author
|
Added a follow-up commit for SELECT wavg(t, INTERVAL '1 day')
FROM (VALUES (tint '5@2000-01-01'), (tint '3@2000-01-02')) tt(t);
-- {[5@..., 4@..., 3@...]} -- avg of (5, 3) = 4 at the overlap day |
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 the temporal-average aggregate:
```sql
SELECT tAvg(t) FROM (VALUES (tint '5@2000-01-01'), (tint '3@2000-01-01')) tt(t);
-- {4@2000-01-01 00:00:00+00} -- avg of 5 and 3
```
Implementation
State holds a `SkipList` of `{sum, count}` pairs (MEOS `double2` layout — `{ double a; double b; }`). `Operation` calls `tnumber_tavg_transfn`. `Combine` merges two states via `temporal_skiplist_splice` with `mduck_datum_sum_double2` as the merge function — a local replica of MEOS's internal `datum_sum_double2` since that symbol is not in the MEOS public install headers (the underlying struct layout is, fortunately, simple enough to replicate exactly). `Finalize` calls `tnumber_tavg_finalfn` which computes per-instant `sum/count` and frees the skiplist; `state.skiplist` is nulled after to keep the destructor from double-freeing.
Test plan