couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [37/50] git commit: Fix _sum reducer for objects with missing keys
Date Sat, 18 Jan 2014 00:48:02 GMT
Fix _sum reducer for objects with missing keys

BugzId: 17391


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/ecf5e315
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/ecf5e315
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/ecf5e315

Branch: refs/heads/import
Commit: ecf5e3152977a8ef3596ad2b27c211215f7443fd
Parents: 9b5ed6b
Author: Mike Wallace <mikewallace1979@googlemail.com>
Authored: Mon Feb 18 16:50:47 2013 +0000
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Fri Jan 17 16:44:31 2014 -0800

----------------------------------------------------------------------
 src/couch_query_servers.erl | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ecf5e315/src/couch_query_servers.erl
----------------------------------------------------------------------
diff --git a/src/couch_query_servers.erl b/src/couch_query_servers.erl
index 88ab30a..d919a85 100644
--- a/src/couch_query_servers.erl
+++ b/src/couch_query_servers.erl
@@ -232,9 +232,9 @@ sum_values(_Else, _Acc) ->
 sum_objects([{K1, V1} | Rest1], [{K1, V2} | Rest2]) ->
     [{K1, sum_values(V1, V2)} | sum_objects(Rest1, Rest2)];
 sum_objects([{K1, V1} | Rest1], [{K2, V2} | Rest2]) when K1 < K2 ->
-    [{K1, V1}, {K2, V2} | sum_objects(Rest1, Rest2)];
+    [{K1, V1} | sum_objects(Rest1, [{K2, V2} | Rest2])];
 sum_objects([{K1, V1} | Rest1], [{K2, V2} | Rest2]) when K1 > K2 ->
-    [{K2, V2}, {K1, V1} | sum_objects(Rest1, Rest2)];
+    [{K2, V2} | sum_objects([{K1, V1} | Rest1], Rest2)];
 sum_objects([], Rest) ->
     Rest;
 sum_objects(Rest, []) ->
@@ -440,9 +440,12 @@ sum_values_test() ->
     ?assertEqual(3, sum_values(1, 2)),
     ?assertEqual([2,4,6], sum_values(1, [1,4,6])),
     ?assertEqual([3,5,7], sum_values([3,2,4], [0,3,3])),
-    X = {[{<<"a">>,1}, {<<"b">>,[1,2]}, {<<"c">>, {[{<<"d">>,3}]}}]},
-    Y = {[{<<"a">>,2}, {<<"b">>,3}, {<<"c">>, {[{<<"e">>,
5}]}}]},
-    Z = {[{<<"a">>,3}, {<<"b">>,[4,2]}, {<<"c">>, {[{<<"d">>,3},{<<"e">>,5}]}}]},
+    X = {[{<<"a">>,1}, {<<"b">>,[1,2]}, {<<"c">>, {[{<<"d">>,3}]}},
+            {<<"g">>,1}]},
+    Y = {[{<<"a">>,2}, {<<"b">>,3}, {<<"c">>, {[{<<"e">>,
5}]}},
+            {<<"f">>,1}, {<<"g">>,1}]},
+    Z = {[{<<"a">>,3}, {<<"b">>,[4,2]}, {<<"c">>, {[{<<"d">>,3},{<<"e">>,5}]}},
+            {<<"f">>,1}, {<<"g">>,2}]},
     ?assertEqual(Z, sum_values(X, Y)),
     ?assertEqual(Z, sum_values(Y, X)).
 


Mime
View raw message