KhushJain opened a new pull request, #4691:
URL: https://github.com/apache/solr/pull/4691
https://issues.apache.org/jira/browse/SOLR-18328
# Description
Added support for the `std(col)` (standard deviation) metric in `rollup()`
streaming expressions.
The `std(col)` metric was non-functional; the `StdMetric` class was a stub
copy-pasted from `MeanMetric` — `update()` was a no-op, `getValue()` returned
`null`, and `newInstance()` even returned a `MeanMetric` instead of a
`StdMetric`.
# Solution
Implemented `StdMetric` to compute the sample standard deviation:
**`StdMetric.java`**:
1. `update()` now accumulates `count`, `sum`, and `sumSq` from the column
value (handling `Double`/`Float`/`Integer`/`Long`, skipping nulls/other types).
2. `getValue()` computes the sample standard deviation `sqrt((n*sumSq -
sum^2) / (n*(n-1)))`, returning `0.0` when `count <= 1`, and honoring
`outputLong` (rounds to a `long` when set).
3. Fixed `newInstance()` to return a `StdMetric` (was incorrectly returning
`MeanMetric`), and replaced the unused `doubleSum`/`longSum` fields with
`sum`/`sumSq`.
# Tests
- **`StreamExpressionTest.testRollupStdMetric`** (new): validates `std(a_i)`
and `std(a_f)` alongside `count(*)` in a `rollup(... over="a_s" ...)`
expression across multiple groups.
- **`StreamingTest.testRollupStream`**: added `StdMetric("a_i")` /
`StdMetric("a_f")` to the metrics array and asserted expected values per group.
# Checklist
Please review the following and check all that apply:
- [x] I have reviewed the guidelines for [How to
Contribute](https://github.com/apache/solr/blob/main/CONTRIBUTING.md) and my
code conforms to the standards described there to the best of my ability.
- [x] I have created a Jira issue and added the issue ID to my pull request
title.
- [x] I have given Solr maintainers
[access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork)
to contribute to my PR branch. (optional but recommended, not available for
branches on forks living under an organisation)
- [x] I have developed this patch against the `main` branch.
- [x] I have run `./gradlew check`.
- [x] I have added tests for my changes.
- [x] I have added documentation for the [Reference
Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide)
- [x] I have added a [changelog
entry](https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc) for my
change
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]