diff options
author | Damien F. Katz <damien@apache.org> | 2009-09-14 22:33:05 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2009-09-14 22:33:05 +0000 |
commit | 8d7a1c6c21fc253a5772350b159d6c2a273f197a (patch) | |
tree | 196e0a5ed4b7c7b9afb0998de3d79a8712f4e6ba /share/www | |
parent | 159ce7f416c430137b2b71f0ef6ffbb6a5c8f2ec (diff) |
View refactoring and addition of raw collationoption. Significant performance improvements in view indexer.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@814893 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www')
-rw-r--r-- | share/www/script/couch_tests.js | 1 | ||||
-rw-r--r-- | share/www/script/test/design_docs.js | 2 | ||||
-rw-r--r-- | share/www/script/test/list_views.js | 2 | ||||
-rw-r--r-- | share/www/script/test/view_collation_raw.js | 123 |
4 files changed, 126 insertions, 2 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index e5426ade..5c1e2bc3 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -74,6 +74,7 @@ loadTest("update_documents.js"); loadTest("utf8.js"); loadTest("uuids.js"); loadTest("view_collation.js"); +loadTest("view_collation_raw.js"); loadTest("view_conflicts.js"); loadTest("view_errors.js"); loadTest("view_include_docs.js"); diff --git a/share/www/script/test/design_docs.js b/share/www/script/test/design_docs.js index 25c36424..82c186f8 100644 --- a/share/www/script/test/design_docs.js +++ b/share/www/script/test/design_docs.js @@ -55,7 +55,7 @@ function() { var vinfo = dinfo.view_index; TEquals(51, vinfo.disk_size); TEquals(false, vinfo.compact_running); - TEquals("64625dce94960fd5ca116e42aa9d011a", vinfo.signature); + TEquals("3f88e53b303e2342e49a66c538c30679", vinfo.signature); db.bulkSave(makeDocs(1, numDocs + 1)); diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js index d845f926..55d34acc 100644 --- a/share/www/script/test/list_views.js +++ b/share/www/script/test/list_views.js @@ -317,7 +317,7 @@ couchTests.list_views = function(debug) { T(!(/Key: 1 /.test(xhr.responseText))); T(/Key: 2/.test(xhr.responseText)); T(/FirstKey: 2/.test(xhr.responseText)); - T(/LastKey: 11/.test(xhr.responseText)); + T(/LastKey: 7/.test(xhr.responseText)); // no multi-key fetch allowed when group=false xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=false", { diff --git a/share/www/script/test/view_collation_raw.js b/share/www/script/test/view_collation_raw.js new file mode 100644 index 00000000..08f37fae --- /dev/null +++ b/share/www/script/test/view_collation_raw.js @@ -0,0 +1,123 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +couchTests.view_collation_raw = function(debug) { + var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"}); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + // NOTE, the values are already in their correct sort order. Consider this + // a specification of collation of json types. + + var values = []; + + // numbers + values.push(1); + values.push(2); + values.push(3); + values.push(4); + + values.push(false); + values.push(null); + values.push(true); + + // then object, compares each key value in the list until different. + // larger objects sort after their subset objects. + values.push({a:1}); + values.push({a:2}); + values.push({b:1}); + values.push({b:2}); + values.push({b:2, a:1}); // Member order does matter for collation. + // CouchDB preserves member order + // but doesn't require that clients will. + // (this test might fail if used with a js engine + // that doesn't preserve order) + values.push({b:2, c:2}); + + // then arrays. compared element by element until different. + // Longer arrays sort after their prefixes + values.push(["a"]); + values.push(["b"]); + values.push(["b","c"]); + values.push(["b","c", "a"]); + values.push(["b","d"]); + values.push(["b","d", "e"]); + + + // then text, case sensitive + values.push("A"); + values.push("B"); + values.push("a"); + values.push("aa"); + values.push("b"); + values.push("ba"); + values.push("bb"); + + for (var i=0; i<values.length; i++) { + db.save({_id:(i).toString(), foo:values[i]}); + } + + var designDoc = { + _id:"_design/test", // turn off couch.js id escaping? + language: "javascript", + views: { + test: {map: "function(doc) { emit(doc.foo, null); }", + options: {collation:"raw"}} + } + } + T(db.save(designDoc).ok); + var rows = db.view("test/test").rows; + for (i=0; i<values.length; i++) { + T(equals(rows[i].key, values[i])); + } + + // everything has collated correctly. Now to check the descending output + rows = db.view("test/test", {descending: true}).rows; + for (i=0; i<values.length; i++) { + T(equals(rows[i].key, values[values.length - 1 -i])); + } + + // now check the key query args + for (i=1; i<values.length; i++) { + rows = db.view("test/test", {key:values[i]}).rows; + T(rows.length == 1 && equals(rows[0].key, values[i])); + } + + // test inclusive_end=true (the default) + // the inclusive_end=true functionality is limited to endkey currently + // if you need inclusive_start=false for startkey, please do implement. ;) + var rows = db.view("test/test", {endkey : "b", inclusive_end:true}).rows; + T(rows[rows.length-1].key == "b") + // descending=true + var rows = db.view("test/test", {endkey : "b", + descending:true, inclusive_end:true}).rows; + T(rows[rows.length-1].key == "b") + + // test inclusive_end=false + var rows = db.view("test/test", {endkey : "b", inclusive_end:false}).rows; + T(rows[rows.length-1].key == "aa") + // descending=true + var rows = db.view("test/test", {endkey : "b", + descending:true, inclusive_end:false}).rows; + T(rows[rows.length-1].key == "ba") + + var rows = db.view("test/test", { + endkey : "b", endkey_docid: "10", + inclusive_end:false}).rows; + T(rows[rows.length-1].key == "aa") + + var rows = db.view("test/test", { + endkey : "b", endkey_docid: "11", + inclusive_end:false}).rows; + T(rows[rows.length-1].key == "aa") +}; |