SOLR-18328 Add support for standard deviation in rollup for streaming expressions - #4691
SOLR-18328 Add support for standard deviation in rollup for streaming expressions#4691KhushJain wants to merge 2 commits into
Conversation
|
Hey @epugh, thanks for reviewing!! One of the existing flaky test failed |
| public void update(Tuple tuple) { | ||
| Object o = tuple.get(columnName); | ||
| double val; | ||
| if (o instanceof Double d) { |
There was a problem hiding this comment.
Could the 'if-else' structure be simplified ?
There was a problem hiding this comment.
there definitly are some unusla coding patterns in the streaming code... but we tend to follow them once they exist as there are so many of them!
There was a problem hiding this comment.
@epugh Thanks for the clarification :) Is there a documentation about the code standard adopted by the codebase ?
@KhushJain Feel free to fix the if-else or ignore my suggestion :)
There was a problem hiding this comment.
we have "tidy" and errrorprone tools that we run int he builds. As far as in the streaming code, nothign formal written, just, look at other java classes ;-). Having said that, I do appreciate your reviewing this PR, and there are lots of PR's out there that need a reviewer to go through them!
There was a problem hiding this comment.
Agreed on the quirky instanceof pattern, but keeping it consistent with all its siblings.
| @Override | ||
| public void update(Tuple tuple) {} | ||
| public void update(Tuple tuple) { | ||
| Object o = tuple.get(columnName); |
There was a problem hiding this comment.
Could the object 'o' be made immutable by declaring it as final ?
There was a problem hiding this comment.
it could be added but the current state is consistent with the existing style.
| @@ -24,15 +24,10 @@ | |||
| import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; | |||
|
|
|||
| public class StdMetric extends Metric { | |||
There was a problem hiding this comment.
Could you include java docs for this class ?
| @@ -89,7 +101,13 @@ public String[] getColumns() { | |||
|
|
|||
| @Override | |||
| public Number getValue() { | |||
There was a problem hiding this comment.
Could you include javadocs to understand the purpose of this method ?
epugh
left a comment
There was a problem hiding this comment.
a question about docs, but otherwise sems to follow the pattern of some other ones.. It would be good to answer the other review comments, and tjhen I think we can move forward...
| * `over`: (Mandatory) A list of fields to group by. | ||
| * `metrics`: (Mandatory) The list of metrics to compute. | ||
| Currently supported metrics are `sum(col)`, `avg(col)`, `min(col)`, `max(col)`, `count(*)`, `missing(col)`, `countDist(col)`, `per(col, percentile)`. | ||
| Currently supported metrics are `sum(col)`, `avg(col)`, `min(col)`, `max(col)`, `count(*)`, `missing(col)`, `countDist(col)`, `per(col, percentile)`, `std(col)`. |
There was a problem hiding this comment.
is there any more docs on these indivdual ones or is this mention what the pattern is? Just wondering if folks will know how to use it...
There was a problem hiding this comment.
no dedicated per-metric docs exists, all streaming metrics are documented this same inline way.
Support for missing(col), countDist(col) and per(col, percentile) are also added by me in the past.
| public void update(Tuple tuple) { | ||
| Object o = tuple.get(columnName); | ||
| double val; | ||
| if (o instanceof Double d) { |
There was a problem hiding this comment.
there definitly are some unusla coding patterns in the streaming code... but we tend to follow them once they exist as there are so many of them!
|
Thanks @epugh @VishnuPriyaChandraSekar for reviewing it!! Can we please back port this to 9x as well? |
VishnuPriyaChandraSekar
left a comment
There was a problem hiding this comment.
Thanks for addressing my feedback :)
https://issues.apache.org/jira/browse/SOLR-18328
Description
Added support for the
std(col)(standard deviation) metric inrollup()streaming expressions.The
std(col)metric was non-functional; theStdMetricclass was a stub copy-pasted fromMeanMetric—update()was a no-op,getValue()returnednull, andnewInstance()even returned aMeanMetricinstead of aStdMetric.Solution
Implemented
StdMetricto compute the sample standard deviation:StdMetric.java:update()now accumulatescount,sum, andsumSqfrom the column value (handlingDouble/Float/Integer/Long, skipping nulls/other types).getValue()computes the sample standard deviationsqrt((n*sumSq - sum^2) / (n*(n-1))), returning0.0whencount <= 1, and honoringoutputLong(rounds to alongwhen set).newInstance()to return aStdMetric(was incorrectly returningMeanMetric), and replaced the unuseddoubleSum/longSumfields withsum/sumSq.Tests
StreamExpressionTest.testRollupStdMetric(new): validatesstd(a_i)andstd(a_f)alongsidecount(*)in arollup(... over="a_s" ...)expression across multiple groups.StreamingTest.testRollupStream: addedStdMetric("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:
mainbranch../gradlew check.