You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2008/06/09 21:55:35 UTC

svn commit: r665852 - in /incubator/couchdb/trunk: share/server/main.js share/www/script/couch_tests.js src/couchdb/couch_btree.erl src/couchdb/couch_db.erl src/couchdb/couch_query_servers.erl src/couchdb/couch_view.erl

Author: damien
Date: Mon Jun  9 12:55:34 2008
New Revision: 665852

URL: http://svn.apache.org/viewvc?rev=665852&view=rev
Log:
Changed name of 'combine' phase of reduce to 'rereduce', to avoid confusion.

Modified:
    incubator/couchdb/trunk/share/server/main.js
    incubator/couchdb/trunk/share/www/script/couch_tests.js
    incubator/couchdb/trunk/src/couchdb/couch_btree.erl
    incubator/couchdb/trunk/src/couchdb/couch_db.erl
    incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl
    incubator/couchdb/trunk/src/couchdb/couch_view.erl

Modified: incubator/couchdb/trunk/share/server/main.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/server/main.js?rev=665852&r1=665851&r2=665852&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/server/main.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/server/main.js [utf-8] Mon Jun  9 12:55:34 2008
@@ -102,13 +102,13 @@
         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 @@
           }
         } else {
           values = cmd[2];
-          is_combine = true;
+          rereduce = true;
         }
 
         for (var i in reduceFuns) {
@@ -130,7 +130,7 @@
         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",

Modified: incubator/couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch_tests.js?rev=665852&r1=665851&r2=665852&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] Mon Jun  9 12:55:34 2008
@@ -351,23 +351,14 @@
 
       
     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 @@
           }
           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};
       };

Modified: incubator/couchdb/trunk/src/couchdb/couch_btree.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_btree.erl?rev=665852&r1=665851&r2=665852&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_btree.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_btree.erl Mon Jun  9 12:55:34 2008
@@ -64,7 +64,7 @@
 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 @@
 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 @@
     ReduceFun =
         fun(reduce, KVs) ->
             length(KVs);
-        (combine, Reds) ->
+        (rereduce, Reds) ->
             lists:sum(Reds)
         end,
     Btree1 = set_options(Btree, [{reduce, ReduceFun}]),

Modified: incubator/couchdb/trunk/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_db.erl?rev=665852&r1=665851&r2=665852&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_db.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_db.erl Mon Jun  9 12:55:34 2008
@@ -440,13 +440,13 @@
 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) ->

Modified: incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl?rev=665852&r1=665851&r2=665852&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl Mon Jun  9 12:55:34 2008
@@ -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 @@
      [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),
         

Modified: incubator/couchdb/trunk/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_view.erl?rev=665852&r1=665851&r2=665852&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_view.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_view.erl Mon Jun  9 12:55:34 2008
@@ -115,9 +115,9 @@
         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 @@
     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 @@
                 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,