Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Division by zero error of Solr StatsComponent for date field in case of no results

I have a number of docs indexed by Solr 3.5, which contain date fields (solr.DateField) among others. Now I do request to Solr component which should return no results:

http://example.com/solr/select?fq=sis_field_int:1000&
stats=true&stats.field=ds_field_date

and get error

HTTP Status 500 - / by zero java.lang.ArithmeticException: / by zero at
org.apache.solr.handler.component.DateStatsValues.addTypeSpecificStats
(StatsValuesFactory.java:384) at ...

If I send request without stats part or specify any non-date stats field instead, I get expected response with no results. It looks like a bug of Solr which tries e.g. to calculate mean value in this case. Unfortunately I've found no references on this problem. Is there some way to bypass or solve the problem?

like image 644
dev4 Avatar asked Feb 20 '12 21:02

dev4


1 Answers

You're right, the problem is computing the mean value:

res.add("mean", new Date(sum / count));

sum and count are both long. When count is zero, of course you get an ArithmeticException. You're actually making stats on a date field which never has a value in your index. The easiest workaround would be making stats on a field which has at least one value, so the count variable would be greather than zero, the division will work, and the stats would be even more meaningful I guess.

You don't get the same error with the same situation using a numeric field, because in that case the sum variable is double, thus the division don't raise error and the result is NaN. In fact, there are different StatsValues implementations based on the field type.

UPDATE
I've opened the SOLR-3160 jira issue and provided a patch which has just been committed. The next release of Solr will contain the fix!

like image 96
javanna Avatar answered Sep 17 '22 19:09

javanna