couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r983307 - in /couchdb/branches/1.0.x: THANKS share/www/script/test/reduce_builtin.js src/couchdb/couch_query_servers.erl
Date Sat, 07 Aug 2010 20:33:33 GMT
Author: jchris
Date: Sat Aug  7 20:33:33 2010
New Revision: 983307

URL: http://svn.apache.org/viewvc?rev=983307&view=rev
Log:
builtin reduce functions more forgiving about trailing whitespace and other characters

Modified:
    couchdb/branches/1.0.x/THANKS
    couchdb/branches/1.0.x/share/www/script/test/reduce_builtin.js
    couchdb/branches/1.0.x/src/couchdb/couch_query_servers.erl

Modified: couchdb/branches/1.0.x/THANKS
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/THANKS?rev=983307&r1=983306&r2=983307&view=diff
==============================================================================
--- couchdb/branches/1.0.x/THANKS (original)
+++ couchdb/branches/1.0.x/THANKS Sat Aug  7 20:33:33 2010
@@ -63,5 +63,6 @@ suggesting improvements or submitting ch
  * Paul Bonser <pib@paulbonser.com>
  * Caleb Land <caleb.land@gmail.com>
  * Juhani Ränkimies <juhani@juranki.com>
+ * Lim Yue Chuan <shasderias@gmail.com>
 
 For a list of authors see the `AUTHORS` file.

Modified: couchdb/branches/1.0.x/share/www/script/test/reduce_builtin.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/test/reduce_builtin.js?rev=983307&r1=983306&r2=983307&view=diff
==============================================================================
--- couchdb/branches/1.0.x/share/www/script/test/reduce_builtin.js (original)
+++ couchdb/branches/1.0.x/share/www/script/test/reduce_builtin.js Sat Aug  7 20:33:33 2010
@@ -72,6 +72,26 @@ couchTests.reduce_builtin = function(deb
     T(result.rows[0].value == 2*(summate(numDocs-i) - summate(i-1)));
   }
 
+  // test for trailing characters after builtin functions, desired behaviour
+  // is to disregard any trailing characters
+  // I think the behavior should be a prefix test, so that even "_statsorama" 
+  // or "_stats\nare\awesome" should work just as "_stats" does. - JChris
+
+  var trailing = ["\u000a", "orama", "\nare\nawesome", " ", "     \n  "];
+
+  for(var i=0; i < trailing.length; i++) {
+    result = db.query(map, "_sum" + trailing[i]);
+    T(result.rows[0].value == 2*summate(numDocs));
+    result = db.query(map, "_count" + trailing[i]);
+    T(result.rows[0].value == 1000);
+    result = db.query(map, "_stats" + trailing[i]);
+    T(result.rows[0].value.sum == 2*summate(numDocs));
+    T(result.rows[0].value.count == 1000);
+    T(result.rows[0].value.min == 1);
+    T(result.rows[0].value.max == 500);
+    T(result.rows[0].value.sumsqr == 2*sumsqr(numDocs));
+  }
+
   db.deleteDb();
   db.createDb();
 

Modified: couchdb/branches/1.0.x/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_query_servers.erl?rev=983307&r1=983306&r2=983307&view=diff
==============================================================================
--- couchdb/branches/1.0.x/src/couchdb/couch_query_servers.erl (original)
+++ couchdb/branches/1.0.x/src/couchdb/couch_query_servers.erl Sat Aug  7 20:33:33 2010
@@ -143,16 +143,16 @@ os_rereduce(Lang, OsRedSrcs, KVs) ->
 
 builtin_reduce(_Re, [], _KVs, Acc) ->
     {ok, lists:reverse(Acc)};
-builtin_reduce(Re, [<<"_sum">>|BuiltinReds], KVs, Acc) ->
+builtin_reduce(Re, [<<"_sum",_/binary>>|BuiltinReds], KVs, Acc) ->
     Sum = builtin_sum_rows(KVs),
     builtin_reduce(Re, BuiltinReds, KVs, [Sum|Acc]);
-builtin_reduce(reduce, [<<"_count">>|BuiltinReds], KVs, Acc) ->
+builtin_reduce(reduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
     Count = length(KVs),
     builtin_reduce(reduce, BuiltinReds, KVs, [Count|Acc]);
-builtin_reduce(rereduce, [<<"_count">>|BuiltinReds], KVs, Acc) ->
+builtin_reduce(rereduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
     Count = builtin_sum_rows(KVs),
     builtin_reduce(rereduce, BuiltinReds, KVs, [Count|Acc]);
-builtin_reduce(Re, [<<"_stats">>|BuiltinReds], KVs, Acc) ->
+builtin_reduce(Re, [<<"_stats",_/binary>>|BuiltinReds], KVs, Acc) ->
     Stats = builtin_stats(Re, KVs),
     builtin_reduce(Re, BuiltinReds, KVs, [Stats|Acc]).
 



Mime
View raw message