You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Robert Newson (JIRA)" <ji...@apache.org> on 2010/08/20 00:52:16 UTC
[jira] Resolved: (COUCHDB-861) Enhance _sum to handle lists of
numbers.
[ https://issues.apache.org/jira/browse/COUCHDB-861?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Robert Newson resolved COUCHDB-861.
-----------------------------------
Fix Version/s: 1.1
Resolution: Fixed
resolved in r987343 on trunk.
> 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
> Fix For: 1.1
>
> Attachments: 0001-COUCHDB-861-enhance-_sum-to-work-with-lists-of-numbe.patch
>
>
> _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.