Repository navigation
MOD-19665: Port the COUNT, SUM, AVG, MIN and MAX reducers to Rust - #11648
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #11648 +/- ##
==========================================
- Coverage 84.12% 83.53% -0.59%
==========================================
Files 643 673 +30
Lines 85128 86222 +1094
Branches 39311 40483 +1172
==========================================
+ Hits 71614 72027 +413
- Misses 13151 13823 +672
- Partials 363 372 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f441d03 to
13b0e2a
Compare
13b0e2a to
89779c9
Compare
`RSValue_ToNumber` and the comparison code each carried a copy of the conversion (follow references and trios, parse strings with `str_to_float`). It is now `Value::to_number`, which both use, so Rust callers can convert without going through the C ABI. `to_number` is `#[inline]`: `RSValue_ToNumber` converts every arithmetic operand of `APPLY`/`FILTER`, and without the hint the extracted call made an APPLY-heavy aggregation about 4% slower in a release build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The per-group logic of the five numeric reducers moves from `count.c`, `sum.c` and `minmax.c` to the `reducers` crate. As with COLLECT, C keeps the argument parsing (`RDCR*_New`) and calls a Rust constructor, and the per-group states live in a `bumpalo` arena owned by the reducer instead of the C block allocator. The three reducers share one shape, a per-group state folded row by row, which is the new `Accumulator` trait. `AccumulatorReducer` runs one, and `reducers_ffi` wires a single set of generic vtable callbacks for all of them, so the unsafe glue exists once. The states must not need dropping, which `AccumulatorReducer::new` checks at compile time, so the vtable sets no `FreeInstance`. A test drives the vtable with interleaved groups, so Miri covers the glue. Behavior is unchanged: numbers are converted as `RSValue_ToNumber` does, empty groups give NaN for SUM/AVG and infinities for MIN/MAX, and MIN/MAX keep the comparisons of C's `MIN`/`MAX` macros, including how they treat NaN. `reducerId` is now 0 for all five (MIN and MAX used to set their own ids), and `Reducer.srckey` is left unset; nothing reads either. Co-Authored-By: Claude Opus 5.5 <[email protected]>
89779c9 to
dce1a7c
Compare
raz-mon
left a comment
There was a problem hiding this comment.
Nice!
Looks good, 1 comment from initial review
|
| /// Boxes an [`AccumulatorReducer`] running `accumulator` and wires its vtable. | ||
| fn into_c_reducer<A: Accumulator>(accumulator: A) -> *mut ffi::Reducer { |
There was a problem hiding this comment.
I would add some comment here to better explain this function, e.g.,:
/// Wraps a Rust accumulator in the C reducer interface and transfers ownership
/// to the caller. Callbacks are specialized for `A`, so they can recover the
/// concrete reducer and group-state types from C's raw pointers.
The caller must release
/// the allocation exactly once through its `Free` callback, which drops the
/// entire Rust object, including the arena holding all per-group states.



Describe the changes in the pull request
RLookupRow_Get,RSValue_ToNumber).reducerscrate, following COLLECT's split. C keeps the argument parsing and calls a Rust constructor, and the per-group states live in abumpaloarena instead of the C block allocator. The five reducers share one shape, a state folded row by row, which is a smallAccumulatortrait. One set of generic vtable callbacks inreducers_ffiserves all of them.MIN/MAXmacros). Further reducers (STDDEV, COUNT_DISTINCT, FIRST_VALUE, ...) can be ported as oneAccumulatoreach.Which additional issues this PR fixes
Main objects this PR modified
reducers::accumulator: theAccumulatortrait andAccumulatorReducer, a#[repr(C)]wrapper with theReducervtable at offset 0, as in COLLECT.reducers::{count, sum, min_max}: the five reducers.reducers_ffi::accumulator:CountReducer_Create,SumReducer_Create,MinMaxReducer_Create, and the generic callbacks.Value::to_number(first commit): the conversionRSValue_ToNumberperforms, extracted so Rust code does not go through the C ABI. It is#[inline]: without the hint, the extracted call measured about 4% slower on an APPLY-heavy aggregation.Mark if applicable
Release Notes
If a release note is required (bug fix / new feature / enhancement), describe the user impact of this PR in the title.
🤖 Generated with Claude Code