You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2008/09/21 00:18:46 UTC
svn commit: r697427 - in /incubator/couchdb/trunk:
share/www/script/couch_tests.js src/couchdb/couch_httpd.erl
Author: jchris
Date: Sat Sep 20 15:18:45 2008
New Revision: 697427
URL: http://svn.apache.org/viewvc?rev=697427&view=rev
Log:
reduce=false closes COUCHDB-76
Modified:
incubator/couchdb/trunk/share/www/script/couch_tests.js
incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
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=697427&r1=697426&r2=697427&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] Sat Sep 20 15:18:45 2008
@@ -539,6 +539,40 @@
},
+ reduce_false: function(debug) {
+ var db = new CouchDB("test_suite_db");
+ db.deleteDb();
+ db.createDb();
+ if (debug) debugger;
+
+ var numDocs = 5;
+ var docs = makeDocs(1,numDocs + 1);
+ T(db.bulkSave(docs).ok);
+ var summate = function(N) {return (N+1)*N/2;};
+
+ var designDoc = {
+ _id:"_design/test",
+ language: "javascript",
+ views: {
+ summate: {map:"function (doc) {emit(doc.integer, doc.integer)};",
+ reduce:"function (keys, values) { return sum(values); };"},
+ }
+ };
+ T(db.save(designDoc).ok);
+
+ // Test that the reduce works
+ var res = db.view('test/summate');
+ T(res.rows.length == 1 && res.rows[0].value == summate(5));
+
+ //Test that we get our docs back
+ res = db.view('test/summate', {reduce: false});
+ T(res.rows.length == 5);
+ for(var i=0; i<5; i++)
+ {
+ T(res.rows[i].value == i+1);
+ }
+ },
+
multiple_rows: function(debug) {
var db = new CouchDB("test_suite_db");
db.deleteDb();
Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=697427&r1=697426&r2=697427&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Sat Sep 20 15:18:45 2008
@@ -35,7 +35,8 @@
start_docid = nil,
end_docid = {},
skip = 0,
- group_level = 0
+ group_level = 0,
+ reduce = true
}).
start_link() ->
@@ -418,7 +419,8 @@
count = Count,
skip = SkipCount,
direction = Dir,
- start_docid = StartDocId
+ start_docid = StartDocId,
+ reduce = Reduce
} = QueryArgs = parse_view_query(Req),
case couch_view:get_map_view({DbName, <<"_design/", DocId/binary>>, ViewName}) of
@@ -433,7 +435,19 @@
{not_found, Reason} ->
case couch_view:get_reduce_view({DbName, <<"_design/", DocId/binary>>, ViewName}) of
{ok, View} ->
- output_reduce_view(Req, View);
+ case Reduce of
+ false ->
+ {reduce, _N, _Lang, MapView} = View,
+ {ok, RowCount} = couch_view:get_row_count(MapView),
+ Start = {StartKey, StartDocId},
+ FoldlFun = make_view_fold_fun(Req, QueryArgs, RowCount,
+ fun couch_view:reduce_to_count/1),
+ FoldAccInit = {Count, SkipCount, undefined, []},
+ FoldResult = couch_view:fold(MapView, Start, Dir, FoldlFun, FoldAccInit),
+ finish_view_fold(Req, RowCount, FoldResult);
+ _ ->
+ output_reduce_view(Req, View)
+ end;
_ ->
throw({not_found, Reason})
end
@@ -940,6 +954,10 @@
Args#view_query_args{group_level=exact};
{"group_level", LevelStr} ->
Args#view_query_args{group_level=list_to_integer(LevelStr)};
+ {"reduce", "true"} ->
+ Args#view_query_args{reduce=true};
+ {"reduce", "false"} ->
+ Args#view_query_args{reduce=false};
_ -> % unknown key
Msg = lists:flatten(io_lib:format(
"Bad URL query key:~s", [Key])),