SOLR-8671: Date statistics: make "sum" a double instead of a long/date

This commit is contained in:
Tomás Fernández Löbbe 2016-02-27 14:02:30 -08:00
parent 126ac9a5fe
commit ae4d77ae48
3 changed files with 11 additions and 8 deletions

View File

@ -332,6 +332,9 @@ Other Changes
* SOLR-8752: Add a test for SizeLimitedDistributedMap and improve javadocs. (shalin)
* SOLR-8671: Date statistics: make "sum" a double instead of a long/date (Tom Hill, Christine Poerschke,
Tommás Fernández Löbbe)
================== 5.5.1 ==================
Bug Fixes

View File

@ -705,7 +705,7 @@ class EnumStatsValues extends AbstractStatsValues<EnumFieldValue> {
*/
class DateStatsValues extends AbstractStatsValues<Date> {
private long sum = 0;
private double sum = 0.0;
double sumOfSquares = 0;
final protected boolean computeSum;
@ -737,7 +737,7 @@ class DateStatsValues extends AbstractStatsValues<Date> {
@Override
protected void updateTypeSpecificStats(NamedList stv) {
if (computeSum) {
sum += ((Date) stv.get("sum")).getTime();
sum += ((Number) stv.get("sum")).doubleValue();
}
if (computeSumOfSquares) {
sumOfSquares += ((Number) stv.get("sumOfSquares")).doubleValue();
@ -784,10 +784,10 @@ class DateStatsValues extends AbstractStatsValues<Date> {
@Override
protected void addTypeSpecificStats(NamedList<Object> res) {
if (statsField.includeInResponse(Stat.sum)) {
res.add("sum", new Date(sum));
res.add("sum", sum);
}
if (statsField.includeInResponse(Stat.mean)) {
res.add("mean", (count > 0) ? new Date(sum / count) : null);
res.add("mean", (count > 0) ? new Date((long)(sum / count)) : null);
}
if (statsField.includeInResponse(Stat.sumOfSquares)) {
res.add("sumOfSquares", sumOfSquares);
@ -807,7 +807,7 @@ class DateStatsValues extends AbstractStatsValues<Date> {
if (count <= 1) {
return 0.0D;
}
return Math.sqrt(((count * sumOfSquares) - (sum * (double)sum))
return Math.sqrt(((count * sumOfSquares) - (sum * sum))
/ (count * (count - 1.0D)));
}
}

View File

@ -482,7 +482,7 @@ public class StatsComponentTest extends AbstractSolrTestCase {
"//long[@name='count'][.='1']",
"//date[@name='min'][.='2015-12-14T09:00:00Z']",
"//date[@name='max'][.='2015-12-14T09:00:00Z']",
"//date[@name='sum'][.='2015-12-14T09:00:00Z']",
"//double[@name='sum'][.='1.4500836E12']",
"//date[@name='mean'][.='2015-12-14T09:00:00Z']",
"//double[@name='sumOfSquares'][.='" + Double.toString(2102742446988960000000000.0)+"']"
);
@ -495,7 +495,7 @@ public class StatsComponentTest extends AbstractSolrTestCase {
"//long[@name='count'][.='3']",
"//date[@name='min'][.='2015-12-14T09:00:00Z']",
"//date[@name='max'][.='2215-12-14T09:00:00Z']",
"//date[@name='sum'][.='2407-11-08T03:00:00Z']",
"//double[@name='sum'][.='1.38172716E13']",
"//date[@name='mean'][.='2115-12-14T09:00:00Z']",
"//double[@name='sumOfSquares'][.='" + Double.toString(83555549895529430000000000.0)+"']",
// The following number matches the number returned by the current solr
@ -826,7 +826,7 @@ public class StatsComponentTest extends AbstractSolrTestCase {
,"//lst[@name='active_dt']/null[@name='min']"
,"//lst[@name='active_dt']/null[@name='max']"
,"//lst[@name='active_dt']/null[@name='mean']"
,"//lst[@name='active_dt']/date[@name='sum'][.='1970-01-01T00:00:00Z']"
,"//lst[@name='active_dt']/double[@name='sum'][.='0.0']"
,"//lst[@name='active_dt']/double[@name='sumOfSquares'][.='0.0']"
,"//lst[@name='active_dt']/double[@name='stddev'][.='0.0']"