From couchdb-commits-return-357-apmail-incubator-couchdb-commits-archive=incubator.apache.org@incubator.apache.org Tue May 20 19:58:01 2008 Return-Path: Delivered-To: apmail-incubator-couchdb-commits-archive@locus.apache.org Received: (qmail 6698 invoked from network); 20 May 2008 19:58:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 May 2008 19:58:01 -0000 Received: (qmail 52023 invoked by uid 500); 20 May 2008 19:58:02 -0000 Delivered-To: apmail-incubator-couchdb-commits-archive@incubator.apache.org Received: (qmail 51995 invoked by uid 500); 20 May 2008 19:58:02 -0000 Mailing-List: contact couchdb-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-commits@incubator.apache.org Received: (qmail 51978 invoked by uid 99); 20 May 2008 19:58:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 May 2008 12:58:02 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 May 2008 19:57:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 95A9723889F3; Tue, 20 May 2008 12:57:37 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r658405 - in /incubator/couchdb/trunk: share/server/main.js share/www/script/couch_tests.js src/couchdb/couch_btree.erl src/couchdb/couch_view.erl Date: Tue, 20 May 2008 19:57:37 -0000 To: couchdb-commits@incubator.apache.org From: damien@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080520195737.95A9723889F3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: damien Date: Tue May 20 12:57:37 2008 New Revision: 658405 URL: http://svn.apache.org/viewvc?rev=658405&view=rev Log: Fixed design document view definitions to be consistent with temp views. Changed the name of the map(K,V) call in the javascript views to emit(K,V) 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_view.erl Modified: incubator/couchdb/trunk/share/server/main.js URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/server/main.js?rev=658405&r1=658404&r2=658405&view=diff ============================================================================== --- incubator/couchdb/trunk/share/server/main.js [utf-8] (original) +++ incubator/couchdb/trunk/share/server/main.js [utf-8] Tue May 20 12:57:37 2008 @@ -16,7 +16,7 @@ var sandbox = null; -map = function(key, value) { +emit = function(key, value) { map_results.push([key, value]); } @@ -32,7 +32,7 @@ try { // if possible, use evalcx (not always available) sandbox = evalcx(''); - sandbox.map = map; + sandbox.emit = emit; sandbox.sum = sum; } catch (e) {} 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=658405&r1=658404&r2=658405&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] Tue May 20 12:57:37 2008 @@ -59,7 +59,7 @@ // has a value of 4, and then returns the document's b value. var mapFunction = function(doc){ if(doc.a==4) - map(null, doc.b); + emit(null, doc.b); }; results = db.query(mapFunction); @@ -208,7 +208,7 @@ } // query all documents, and return the doc.integer member as a key. - results = db.query(function(doc){ map(doc.integer, null) }); + results = db.query(function(doc){ emit(doc.integer, null) }); T(results.total_rows == numDocsToCreate); @@ -218,7 +218,7 @@ } // do the query again, but with descending output - results = db.query(function(doc){ map(doc.integer, null) }, {descending:true}); + results = db.query(function(doc){ emit(doc.integer, null) }, {descending:true}); T(results.total_rows == numDocsToCreate); @@ -238,7 +238,7 @@ T(db.bulkSave(docs).ok); var summate = function(N) {return (N+1)*N/2;}; - var map = function (doc) {map(doc.integer, doc.integer)}; + var map = function (doc) {emit(doc.integer, doc.integer)}; var reduce = function (keys, values) { return sum(values); }; var result = db.reduce_query(map, reduce).result; T(result == summate(numDocs)); @@ -277,7 +277,7 @@ var generateListOfCitiesAndState = "function(doc) {" + " for (var i = 0; i < doc.cities.length; i++)" + - " map(doc.cities[i] + \", \" + doc._id, null);" + + " emit(doc.cities[i] + \", \" + doc._id, null);" + "}"; var results = db.query(generateListOfCitiesAndState); @@ -348,7 +348,7 @@ // query all documents, and return the doc.foo member as a key. results = db.query(function(doc){ - map(null, doc.longtest); + emit(null, doc.longtest); }); }, @@ -376,7 +376,7 @@ } // check that views and key collation don't blow up - var rows = db.query(function(doc) { map(null, doc.text) }).rows; + var rows = db.query(function(doc) { emit(null, doc.text) }).rows; for (var i=0; i % got full node, return the already calculated reduction {[], [{nil, {P, R}}]}; false -> % otherwise return the keyvalues for later reduction - {KVs2, []} + {[assemble(Bt,K,V) || {K,V} <- KVs2], []} end end. @@ -568,9 +568,10 @@ stream_kv_node2(_Bt, _Reds, _PrevKVs, [], _Dir, _Fun, Acc) -> {ok, Acc}; stream_kv_node2(Bt, Reds, PrevKVs, [{K,V} | RestKVs], Dir, Fun, Acc) -> - case Fun(assemble(Bt, K, V), {PrevKVs, Reds}, Acc) of + AssembledKV = assemble(Bt, K, V), + case Fun(AssembledKV, {PrevKVs, Reds}, Acc) of {ok, Acc2} -> - stream_kv_node2(Bt, Reds, [{K,V} | PrevKVs], RestKVs, Dir, Fun, Acc2); + stream_kv_node2(Bt, Reds, [AssembledKV | PrevKVs], RestKVs, Dir, Fun, Acc2); {stop, Acc2} -> {stop, Acc2} end. Modified: incubator/couchdb/trunk/src/couchdb/couch_view.erl URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_view.erl?rev=658405&r1=658404&r2=658405&view=diff ============================================================================== --- incubator/couchdb/trunk/src/couchdb/couch_view.erl (original) +++ incubator/couchdb/trunk/src/couchdb/couch_view.erl Tue May 20 12:57:37 2008 @@ -155,32 +155,26 @@ design_doc_to_view_group(#doc{id=Id,body={obj, Fields}}) -> Language = proplists:get_value("language", Fields, "javascript"), {obj, RawViews} = proplists:get_value("views", Fields, {obj, []}), - - % extract the map/reduce views from the json fields and into lists - MapViewsRaw = [{Name, Src, nil} || {Name, Src} <- RawViews, is_list(Src)], - MapReduceViewsRaw = - [{Name, - proplists:get_value("map", MRFuns), - proplists:get_value("reduce", MRFuns)} - || {Name, {obj, MRFuns}} <- RawViews], % add the views to a dictionary object, with the map source as the key DictBySrc = lists:foldl( - fun({Name, MapSrc, RedSrc}, DictBySrcAcc) -> + fun({Name, {obj, MRFuns}}, DictBySrcAcc) -> + MapSrc = proplists:get_value("map", MRFuns), + RedSrc = proplists:get_value("reduce", MRFuns, null), View = case dict:find(MapSrc, DictBySrcAcc) of {ok, View0} -> View0; error -> #view{def=MapSrc} % create new view object end, View2 = - if RedSrc == nil -> + if RedSrc == null -> View#view{map_names=[Name|View#view.map_names]}; true -> View#view{reduce_funs=[{Name,RedSrc}|View#view.reduce_funs]} end, dict:store(MapSrc, View2, DictBySrcAcc) - end, dict:new(), MapViewsRaw ++ MapReduceViewsRaw), + end, dict:new(), RawViews), % number the views {Views, _N} = lists:mapfoldl( fun({_Src, View}, N) ->