diff options
-rw-r--r-- | share/server/main.js | 8 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 26 | ||||
-rw-r--r-- | src/couchdb/couch_btree.erl | 6 | ||||
-rw-r--r-- | src/couchdb/couch_db.erl | 4 | ||||
-rw-r--r-- | src/couchdb/couch_query_servers.erl | 8 | ||||
-rw-r--r-- | src/couchdb/couch_view.erl | 10 |
6 files changed, 31 insertions, 31 deletions
diff --git a/share/server/main.js b/share/server/main.js index 7fe08608..9773cf6c 100644 --- a/share/server/main.js +++ b/share/server/main.js @@ -102,13 +102,13 @@ while (cmd = eval(readline())) { print(toJSON(buf)); break; - case "combine": + case "rereduce": case "reduce": { var keys = null; var values = null; var reduceFuns = cmd[1]; - var is_combine = false; + var rereduce = false; if (cmd[0] == "reduce") { var kvs = cmd[2]; @@ -120,7 +120,7 @@ while (cmd = eval(readline())) { } } else { values = cmd[2]; - is_combine = true; + rereduce = true; } for (var i in reduceFuns) { @@ -130,7 +130,7 @@ while (cmd = eval(readline())) { var reductions = new Array(funs.length); for(var i = 0; i < reduceFuns.length; i++) { try { - reductions[i] = reduceFuns[i](keys, values, is_combine); + reductions[i] = reduceFuns[i](keys, values, rereduce); } catch (err) { if (err == "fatal_error") { throw {error: "reduce_runtime_error", diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index cbec817e..97a2bb17 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -351,23 +351,14 @@ var tests = { var map = function (doc) {emit(null, doc.val)}; - var reduceCombine = function (keys, values, combine) { + var reduceCombine = function (keys, values, rereduce) { // This computes the standard deviation of the mapped results var stdDeviation=0; var count=0; var total=0; var sqrTotal=0; - if (combine) { - // This is the combine phase, we are re-reducing previosuly returned - // reduce values. - for(var i in values) { - count = count + values[i].count; - total = total + values[i].total; - sqrTotal = sqrTotal + (values[i].sqrTotal * values[i].sqrTotal); - } - } - else { + if (!rereduce) { // This is the reduce phase, we are reducing over emitted values from // the map functions. for(var i in values) { @@ -376,12 +367,21 @@ var tests = { } count = values.length; } + else { + // This is the rereduce phase, we are re-reducing previosuly + // reduced values. + for(var i in values) { + count = count + values[i].count; + total = total + values[i].total; + sqrTotal = sqrTotal + (values[i].sqrTotal * values[i].sqrTotal); + } + } var variance = (sqrTotal - ((total * total)/count)) / count; stdDeviation = Math.sqrt(variance); - // the reduce result. It contains enough information to combine with - // more reduce results, and the final output values. + // the reduce result. It contains enough information to be rereduced + // with other reduce results. return {"stdDeviation":stdDeviation,"count":count, "total":total,"sqrTotal":sqrTotal}; }; diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl index f01234c1..b9374f91 100644 --- a/src/couchdb/couch_btree.erl +++ b/src/couchdb/couch_btree.erl @@ -64,7 +64,7 @@ final_reduce(Reduce, {[], []}) -> final_reduce(_Bt, {[], [Red]}) -> Red; final_reduce(Reduce, {[], Reductions}) -> - Reduce(combine, Reductions); + Reduce(rereduce, Reductions); final_reduce(Reduce, {KVs, Reductions}) -> Red = Reduce(reduce, KVs), final_reduce(Reduce, {[], [Red | Reductions]}). @@ -289,7 +289,7 @@ modify_node(Bt, RootPointerInfo, Actions, QueryOutput) -> reduce_node(#btree{reduce=nil}, _NodeType, _NodeList) -> []; reduce_node(#btree{reduce=R}, kp_node, NodeList) -> - R(combine, [Red || {_K, {_P, Red}} <- NodeList]); + R(rereduce, [Red || {_K, {_P, Red}} <- NodeList]); reduce_node(#btree{reduce=R}, kv_node, NodeList) -> R(reduce, NodeList). @@ -658,7 +658,7 @@ test_btree(KeyValues) -> ReduceFun = fun(reduce, KVs) -> length(KVs); - (combine, Reds) -> + (rereduce, Reds) -> lists:sum(Reds) end, Btree1 = set_options(Btree, [{reduce, ReduceFun}]), diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl index 844c9260..66b18976 100644 --- a/src/couchdb/couch_db.erl +++ b/src/couchdb/couch_db.erl @@ -440,13 +440,13 @@ btree_by_id_join(Id, {Seq, Deleted, Tree}) -> btree_by_id_reduce(reduce, FullDocInfos) -> % count the number of deleted documents length([1 || #full_doc_info{deleted=false} <- FullDocInfos]); -btree_by_id_reduce(combine, Reds) -> +btree_by_id_reduce(rereduce, Reds) -> lists:sum(Reds). btree_by_seq_reduce(reduce, DocInfos) -> % count the number of deleted documents length(DocInfos); -btree_by_seq_reduce(combine, Reds) -> +btree_by_seq_reduce(rereduce, Reds) -> lists:sum(Reds). init_db(DbName, Filepath, Fd, Header) -> diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl index 1fb2462c..ffacbc26 100644 --- a/src/couchdb/couch_query_servers.erl +++ b/src/couchdb/couch_query_servers.erl @@ -17,7 +17,7 @@ -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3,stop/0]). -export([start_doc_map/2, map_docs/2, stop_doc_map/1]). --export([reduce/3, combine/3]). +-export([reduce/3, rereduce/3]). -export([test/0, test/1]). -include("couch_db.hrl"). @@ -141,15 +141,15 @@ group_reductions_results(List) -> [Heads | group_reductions_results(Tails)] end. -combine(_Lang, [], _ReducedValues) -> +rereduce(_Lang, [], _ReducedValues) -> {ok, []}; -combine(Lang, RedSrcs, ReducedValues) -> +rereduce(Lang, RedSrcs, ReducedValues) -> Port = get_linked_port(Lang), Grouped = group_reductions_results(ReducedValues), Results = lists:zipwith( fun(FunSrc, Values) -> {true, {Result}} = - prompt(Port, {"combine", {FunSrc}, list_to_tuple(Values)}), + prompt(Port, {"rereduce", {FunSrc}, list_to_tuple(Values)}), Result end, RedSrcs, Grouped), diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl index c44a9ba8..ee493c7d 100644 --- a/src/couchdb/couch_view.erl +++ b/src/couchdb/couch_view.erl @@ -115,9 +115,9 @@ fold_reduce({reduce, NthRed, Lang, #view{btree=Bt, reduce_funs=RedFuns}}, Dir, S fun(reduce, KVs) -> {ok, Reduced} = couch_query_servers:reduce(Lang, [FunSrc], KVs), {0, PreResultPadding ++ Reduced ++ PostResultPadding}; - (combine, Reds) -> + (rereduce, Reds) -> UserReds = [[lists:nth(NthRed, UserRedsList)] || {_, UserRedsList} <- Reds], - {ok, Reduced} = couch_query_servers:combine(Lang, [FunSrc], UserReds), + {ok, Reduced} = couch_query_servers:rereduce(Lang, [FunSrc], UserReds), {0, PreResultPadding ++ Reduced ++ PostResultPadding} end, WrapperFun = fun({GroupedKey, _}, PartialReds, Acc0) -> @@ -154,7 +154,7 @@ reduce_to_count(Reductions) -> couch_btree:final_reduce( fun(reduce, KVs) -> {length(KVs), []}; - (combine, Reds) -> + (rereduce, Reds) -> {lists:sum([Count0 || {Count0, _} <- Reds]), []} end, Reductions), Count. @@ -485,10 +485,10 @@ disk_group_to_mem(Db, Fd, #group{id_btree=IdState,def_lang=Lang,views=Views}=Gro fun(reduce, KVs) -> {ok, Reduced} = couch_query_servers:reduce(Lang, FunSrcs, KVs), {length(KVs), Reduced}; - (combine, Reds) -> + (rereduce, Reds) -> Count = lists:sum([Count0 || {Count0, _} <- Reds]), UserReds = [UserRedsList || {_, UserRedsList} <- Reds], - {ok, Reduced} = couch_query_servers:combine(Lang, FunSrcs, UserReds), + {ok, Reduced} = couch_query_servers:rereduce(Lang, FunSrcs, UserReds), {Count, Reduced} end, {ok, Btree} = couch_btree:open(BtreeState, Fd, |