couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject svn commit: r1064798 - in /couchdb/trunk: share/www/script/test/reduce.js src/couchdb/couch_btree.erl
Date Fri, 28 Jan 2011 17:47:14 GMT
Author: rnewson
Date: Fri Jan 28 17:47:13 2011
New Revision: 1064798

URL: http://svn.apache.org/viewvc?rev=1064798&view=rev
Log:
COUCHDB-1047 - support inclusive_end with reduce calls

Modified:
    couchdb/trunk/share/www/script/test/reduce.js
    couchdb/trunk/src/couchdb/couch_btree.erl

Modified: couchdb/trunk/share/www/script/test/reduce.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/reduce.js?rev=1064798&r1=1064797&r2=1064798&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/reduce.js (original)
+++ couchdb/trunk/share/www/script/test/reduce.js Fri Jan 28 17:47:13 2011
@@ -100,6 +100,21 @@ couchTests.reduce = function(debug) {
     T(equals(results.rows[4], {key:["d","a"],value:10*i}));
     T(equals(results.rows[5], {key:["d","b"],value:10*i}));
     T(equals(results.rows[6], {key:["d","c"],value:10*i}));
+
+    // endkey test with inclusive_end=true
+    var results = db.query(map, reduce, {group_level:2,endkey:["d"],inclusive_end:true});
+    T(equals(results.rows[0], {key:["a"],value:20*i}));
+    T(equals(results.rows[1], {key:["a","b"],value:40*i}));
+    T(equals(results.rows[2], {key:["a","c"],value:10*i}));
+    T(equals(results.rows[3], {key:["d"],value:10*i}));
+    TEquals(4, results.rows.length);
+
+    // endkey test with inclusive_end=false
+    var results = db.query(map, reduce, {group_level:2,endkey:["d"],inclusive_end:false});
+    T(equals(results.rows[0], {key:["a"],value:20*i}));
+    T(equals(results.rows[1], {key:["a","b"],value:40*i}));
+    T(equals(results.rows[2], {key:["a","c"],value:10*i}));
+    TEquals(3, results.rows.length);
   }
 
   // now test out more complex reductions that need to use the combine option.

Modified: couchdb/trunk/src/couchdb/couch_btree.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_btree.erl?rev=1064798&r1=1064797&r2=1064798&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_btree.erl (original)
+++ couchdb/trunk/src/couchdb/couch_btree.erl Fri Jan 28 17:47:13 2011
@@ -64,7 +64,10 @@ final_reduce(Reduce, {KVs, Reductions}) 
 fold_reduce(#btree{root=Root}=Bt, Fun, Acc, Options) ->
     Dir = couch_util:get_value(dir, Options, fwd),
     StartKey = couch_util:get_value(start_key, Options),
-    EndKey = couch_util:get_value(end_key, Options),
+    EndKey = case couch_util:get_value(end_key_gt, Options) of
+        undefined -> couch_util:get_value(end_key, Options);
+        LastKey -> LastKey
+    end,
     KeyGroupFun = couch_util:get_value(key_group_fun, Options, fun(_,_) -> true end),
     {StartKey2, EndKey2} =
     case Dir of



Mime
View raw message