summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2018-05-28 12:23:47 -0400
committerAdam Kocoloski <kocolosk@apache.org>2018-05-28 12:23:47 -0400
commit5802afd342b10a39d2266f4244b3607e03d94be3 (patch)
tree827e3428724eae93258ebd1dad63dc1e0c91da69
parent9122d458770d5df34bfdf3d8831600cebaa5e280 (diff)
downloadcouchdb-5802afd342b10a39d2266f4244b3607e03d94be3.tar.gz
Rename to _approx_count_distinct and return an int
-rw-r--r--src/couch/src/couch_query_servers.erl10
-rw-r--r--src/couch_mrview/src/couch_mrview.erl2
2 files changed, 6 insertions, 6 deletions
diff --git a/src/couch/src/couch_query_servers.erl b/src/couch/src/couch_query_servers.erl
index 42b0a4de7..02d90f195 100644
--- a/src/couch/src/couch_query_servers.erl
+++ b/src/couch/src/couch_query_servers.erl
@@ -91,7 +91,7 @@ finalize(Reductions) ->
{ok, lists:map(fun(Reduction) ->
case hyper:is_hyper(Reduction) of
true ->
- hyper:card(Reduction);
+ round(hyper:card(Reduction));
false ->
Reduction
end
@@ -183,8 +183,8 @@ builtin_reduce(rereduce, [<<"_count",_/binary>>|BuiltinReds], KVs, Acc) ->
builtin_reduce(Re, [<<"_stats",_/binary>>|BuiltinReds], KVs, Acc) ->
Stats = builtin_stats(Re, KVs),
builtin_reduce(Re, BuiltinReds, KVs, [Stats|Acc]);
-builtin_reduce(Re, [<<"_distinct",_/binary>>|BuiltinReds], KVs, Acc) ->
- Distinct = count_distinct_keys(Re, KVs),
+builtin_reduce(Re, [<<"_approx_count_distinct",_/binary>>|BuiltinReds], KVs, Acc) ->
+ Distinct = approx_count_distinct(Re, KVs),
builtin_reduce(Re, BuiltinReds, KVs, [Distinct|Acc]).
@@ -318,11 +318,11 @@ get_number(Key, Props) ->
end.
% TODO allow customization of precision in the ddoc.
-count_distinct_keys(reduce, KVs) ->
+approx_count_distinct(reduce, KVs) ->
lists:foldl(fun([[Key, _Id], _Value], Filter) ->
hyper:insert(term_to_binary(Key), Filter)
end, hyper:new(11), KVs);
-count_distinct_keys(rereduce, Reds) ->
+approx_count_distinct(rereduce, Reds) ->
hyper:union([Filter || [_, Filter] <- Reds]).
% use the function stored in ddoc.validate_doc_update to test an update.
diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index 64e05845c..b417aac52 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -184,7 +184,7 @@ validate(DbName, DDoc) ->
ok;
({_RedName, <<"_stats", _/binary>>}) ->
ok;
- ({_RedName, <<"_distinct", _/binary>>}) ->
+ ({_RedName, <<"_approx_count_distinct", _/binary>>}) ->
ok;
({_RedName, <<"_", _/binary>> = Bad}) ->
Msg = ["`", Bad, "` is not a supported reduce function."],