Skip to content

Loading…

Empty keys result #24

Closed
wants to merge 2 commits into from

2 participants

@adamlofts

This pull request restores the behaviour of couchdb 1.2 which is to return no rows when passed an empty array as the keys parameter to a query.

adamlofts added some commits
@adamlofts adamlofts Add test cases for empty keys query parameter ee3690e
@adamlofts adamlofts Differentiate between keys=undefined and keys=[] in query
This commit restores the 1.2 behavior of returning no results when passed an empty keys array.
dc17b53
@janl

Can you explain which version of CouchDB has which behaviour and for which version you are fixing this?

I looked through 1.0.x, 1.1.x, 1.2.x & master and couldn't find a conclusive answer :)

@adamlofts

I've tried versions 1.1.x and 1.2.x which both return no results with keys=[]. I can't build 1.0.x.
The regression is on master which returns all documents with keys=[] and its master I intended the fix for.

I've just tried cherry picking first commit which just tests this functionality onto 1.2.x and the test cases all pass so you could pull that commit onto 1.2.x.

@janl

Merged, thanks!

@adamlofts adamlofts closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 20, 2012
  1. @adamlofts
  2. @adamlofts

    Differentiate between keys=undefined and keys=[] in query

    adamlofts committed
    This commit restores the 1.2 behavior of returning no results when passed an empty keys array.
This page is out of date. Refresh to see the latest.
View
4 share/www/script/test/view_multi_key_all_docs.js
@@ -88,4 +88,8 @@ couchTests.view_multi_key_all_docs = function(debug) {
T(rows[1].error == "not_found");
T(!rows[1].id);
T(rows[2].id == rows[2].key && rows[2].key == "0");
+
+ // empty keys
+ rows = db.allDocs({keys: []}, null).rows;
+ T(rows.length == 0);
};
View
4 share/www/script/test/view_multi_key_design.js
@@ -61,6 +61,10 @@ couchTests.view_multi_key_design = function(debug) {
T(rows[i].key == rows[i].value);
}
+ // with empty keys
+ rows = db.view("test/all_docs",{keys:[]},null).rows;
+ T(rows.length == 0);
+
var reduce = db.view("test/summate",{group:true},keys).rows;
T(reduce.length == keys.length);
for(var i=0; i<reduce.length; i++) {
View
3 share/www/script/test/view_multi_key_temp.js
@@ -34,4 +34,7 @@ couchTests.view_multi_key_temp = function(debug) {
T(keys.indexOf(reduce[i].key) != -1);
T(reduce[i].key == reduce[i].value);
}
+
+ rows = db.query(queryFun, null, {}, []).rows;
+ T(rows.length == 0);
};
View
8 src/couch_mrview/src/couch_mrview_util.erl
@@ -260,7 +260,8 @@ all_docs_reduce_to_count(Reductions) ->
{Count, _, _} = couch_btree:final_reduce(Reduce, Reductions),
Count.
-
+reduce_to_count(nil) ->
+ 0;
reduce_to_count(Reductions) ->
Reduce = fun
(reduce, KVs) ->
@@ -592,10 +593,7 @@ ad_ekey_opts(#mrargs{end_key_docid=EKeyDocId}=Args) ->
key_opts(Args) ->
key_opts(Args, []).
-
-key_opts(#mrargs{keys=undefined}=Args, Extra) ->
- key_opts(Args#mrargs{keys=[]}, Extra);
-key_opts(#mrargs{keys=[], direction=Dir}=Args, Extra) ->
+key_opts(#mrargs{keys=undefined, direction=Dir}=Args, Extra) ->
[[{dir, Dir}] ++ skey_opts(Args) ++ ekey_opts(Args) ++ Extra];
key_opts(#mrargs{keys=Keys, direction=Dir}=Args, Extra) ->
lists:map(fun(K) ->
Something went wrong with that request. Please try again.