diff options
-rw-r--r-- | apps/couch/src/couch_btree.erl | 5 | ||||
-rw-r--r-- | rel/overlay/share/www/script/test/reduce.js | 15 |
2 files changed, 19 insertions, 1 deletions
diff --git a/apps/couch/src/couch_btree.erl b/apps/couch/src/couch_btree.erl index 4ed3fe54..5b950dc1 100644 --- a/apps/couch/src/couch_btree.erl +++ b/apps/couch/src/couch_btree.erl @@ -76,7 +76,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 diff --git a/rel/overlay/share/www/script/test/reduce.js b/rel/overlay/share/www/script/test/reduce.js index 979a0292..16c7a7bf 100644 --- a/rel/overlay/share/www/script/test/reduce.js +++ b/rel/overlay/share/www/script/test/reduce.js @@ -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. |