From f3457b227060940591ffb13868d218a4f4903ee6 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Thu, 23 Dec 2010 00:07:41 -0500 Subject: Handle empty result set correctly in _stats BugzID: 11498 --- apps/couch/src/couch_query_servers.erl | 3 +++ 1 file changed, 3 insertions(+) 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)}; -- cgit v1.2.3