diff options
author | Adam Kocoloski <adam@cloudant.com> | 2010-12-23 00:07:41 -0500 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2011-02-25 13:03:16 -0500 |
commit | f3457b227060940591ffb13868d218a4f4903ee6 (patch) | |
tree | 525865025598d17c18b05ac0b9f037d8e5125075 /apps | |
parent | 9607ad9984b1099cf8b57861af5ca5f0419d14b7 (diff) |
Handle empty result set correctly in _stats
BugzID: 11498
Diffstat (limited to 'apps')
-rw-r--r-- | apps/couch/src/couch_query_servers.erl | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/apps/couch/src/couch_query_servers.erl b/apps/couch/src/couch_query_servers.erl index 4e86dcf4..58540660 100644 --- a/apps/couch/src/couch_query_servers.erl +++ b/apps/couch/src/couch_query_servers.erl @@ -143,6 +143,9 @@ builtin_sum_rows(KVs) -> throw({invalid_value, <<"builtin _sum function requires map values to be numbers">>}) end, 0, KVs). +builtin_stats(_, []) -> + {[{sum,0}, {count,0}, {min,0}, {max,0}, {sumsqr,0}]}; + builtin_stats(reduce, [[_,First]|Rest]) when is_number(First) -> Stats = lists:foldl(fun([_K,V], {S,C,Mi,Ma,Sq}) when is_number(V) -> {S+V, C+1, erlang:min(Mi,V), erlang:max(Ma,V), Sq+(V*V)}; |