couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Newson (JIRA)" <j...@apache.org>
Subject [jira] Created: (COUCHDB-861) Enhance _sum to handle lists of numbers.
Date Thu, 19 Aug 2010 12:17:16 GMT
Enhance _sum to handle lists of numbers.
----------------------------------------

                 Key: COUCHDB-861
                 URL: https://issues.apache.org/jira/browse/COUCHDB-861
             Project: CouchDB
          Issue Type: Improvement
          Components: Database Core
            Reporter: Robert Newson


_sum can currently only sum a single value but it is often useful to emit an array of numbers
on the value side.

The code below achieves this, I'm working on a test.


diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl
index 92c30f8..e2a748e 100644
--- a/src/couchdb/couch_query_servers.erl
+++ b/src/couchdb/couch_query_servers.erl
@@ -167,8 +167,13 @@ builtin_sum_rows(KVs) ->
     lists:foldl(fun
         ([_Key, Value], Acc) when is_number(Value) ->
             Acc + Value;
+        ([_Key, Value], Acc) when is_list(Value) ->
+            case Acc of
+                0 -> Value;
+                _ -> lists:zipwith(fun(X, Y) -> X + Y end, Acc, Value)
+            end;
         (_Else, _Acc) ->
-            throw({invalid_value, <<"builtin _sum function requires map values to be
numbers
+            throw({invalid_value, <<"builtin _sum function requires map values to be
numbers
     end, 0, KVs).
 
 builtin_stats(reduce, [[_,First]|Rest]) when is_number(First) ->


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message