You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2018/05/31 17:23:22 UTC
[couchdb] 01/01: Add JS integration tests for _approx_count_distinct
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch add-js-tests-for-approx-count-distinct
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit bac71a9cf808a09a8333afbe6e08dad55224511c
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu May 31 13:20:45 2018 -0400
Add JS integration tests for _approx_count_distinct
Jira: COUCHDB-2971
---
test/javascript/tests/reduce_builtin.js | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/test/javascript/tests/reduce_builtin.js b/test/javascript/tests/reduce_builtin.js
index 9c455e4..4686841 100644
--- a/test/javascript/tests/reduce_builtin.js
+++ b/test/javascript/tests/reduce_builtin.js
@@ -37,6 +37,12 @@ couchTests.reduce_builtin = function(debug) {
emit(doc.integer, doc.integer);
};
+ var check_approx_distinct = function(expected, estimated) {
+ // see https://en.wikipedia.org/wiki/HyperLogLog
+ var err = 1.04 / Math.sqrt(Math.pow(2, 11 - 1));
+ return Math.abs(expected - estimated) < expected * err;
+ };
+
var result = db.query(map, "_sum");
T(result.rows[0].value == 2*summate(numDocs));
result = db.query(map, "_count");
@@ -47,27 +53,41 @@ couchTests.reduce_builtin = function(debug) {
T(result.rows[0].value.min == 1);
T(result.rows[0].value.max == 500);
T(result.rows[0].value.sumsqr == 2*sumsqr(numDocs));
+ result = db.query(map, "_approx_count_distinct");
+ T(check_approx_distinct(numDocs, result.rows[0].value));
result = db.query(map, "_sum", {startkey: 4, endkey: 4});
T(result.rows[0].value == 8);
result = db.query(map, "_count", {startkey: 4, endkey: 4});
T(result.rows[0].value == 2);
+ result = db.query(map, "_approx_count_distinct", {startkey:4, endkey:4});
+ T(check_approx_distinct(1, result.rows[0].value));
result = db.query(map, "_sum", {startkey: 4, endkey: 5});
T(result.rows[0].value == 18);
result = db.query(map, "_count", {startkey: 4, endkey: 5});
T(result.rows[0].value == 4);
+ result = db.query(map, "_approx_count_distinct", {startkey:4, endkey:5});
+ T(check_approx_distinct(2, result.rows[0].value));
+
result = db.query(map, "_sum", {startkey: 4, endkey: 6});
T(result.rows[0].value == 30);
result = db.query(map, "_count", {startkey: 4, endkey: 6});
T(result.rows[0].value == 6);
+ result = db.query(map, "_approx_count_distinct", {startkey: 4, endkey: 6});
+ T(check_approx_distinct(3, result.rows[0].value));
result = db.query(map, "_sum", {group:true, limit:3});
T(result.rows[0].value == 2);
T(result.rows[1].value == 4);
T(result.rows[2].value == 6);
+ result = db.query(map, "_approx_count_distinct", {group:true, limit:3});
+ T(check_approx_distinct(1, result.rows[0].value));
+ T(check_approx_distinct(1, result.rows[1].value));
+ T(check_approx_distinct(1, result.rows[2].value));
+
for(var i=1; i<numDocs/2; i+=30) {
result = db.query(map, "_sum", {startkey: i, endkey: numDocs - i});
T(result.rows[0].value == 2*(summate(numDocs-i) - summate(i-1)));
--
To stop receiving notification emails like this one, please contact
vatamane@apache.org.