You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2015/06/30 04:46:42 UTC
[3/4] couch-mrview commit: updated
refs/heads/1805-respect-collation-setting-reduce-group to ba84fb8
Add a failing test for reduce key grouping
I needed to refactor a few things to support multiple ddocs in the
collation test module.
COUCHDB-1805
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/14f5bba6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/14f5bba6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/14f5bba6
Branch: refs/heads/1805-respect-collation-setting-reduce-group
Commit: 14f5bba64b8525f65d70b59e6bf77954fdcded6e
Parents: 2dc7649
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Mon Jun 29 21:42:40 2015 -0400
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Mon Jun 29 22:45:41 2015 -0400
----------------------------------------------------------------------
src/couch_mrview_test_util.erl | 11 ++++++++++-
test/couch_mrview_collation_tests.erl | 15 +++++++++++++--
test/couch_mrview_red_views_tests.erl | 2 +-
3 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/14f5bba6/src/couch_mrview_test_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_test_util.erl b/src/couch_mrview_test_util.erl
index 153d8ea..8cebd6d 100644
--- a/src/couch_mrview_test_util.erl
+++ b/src/couch_mrview_test_util.erl
@@ -89,7 +89,7 @@ ddoc(map) ->
]});
ddoc(red) ->
couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/bar">>},
+ {<<"_id">>, <<"_design/red">>},
{<<"views">>, {[
{<<"baz">>, {[
{<<"map">>, <<
@@ -98,6 +98,15 @@ ddoc(red) ->
"}\n"
>>},
{<<"reduce">>, <<"function(keys, vals) {return sum(vals);}">>}
+ ]}},
+ {<<"zing">>, {[
+ {<<"map">>, <<
+ "function(doc) {\n"
+ " if(doc.foo !== undefined)\n"
+ " emit(doc.foo, null);\n"
+ "}"
+ >>},
+ {<<"reduce">>, <<"_count">>}
]}}
]}}
]}).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/14f5bba6/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_collation_tests.erl b/test/couch_mrview_collation_tests.erl
index 4a03359..c4a714d 100644
--- a/test/couch_mrview_collation_tests.erl
+++ b/test/couch_mrview_collation_tests.erl
@@ -58,7 +58,8 @@
setup() ->
{ok, Db1} = couch_mrview_test_util:new_db(?tempdb(), map),
- {ok, Db2} = couch_mrview_test_util:save_docs(Db1, make_docs()),
+ Docs = [couch_mrview_test_util:ddoc(red) | make_docs()],
+ {ok, Db2} = couch_mrview_test_util:save_docs(Db1, Docs),
Db2.
teardown(Db) ->
@@ -84,7 +85,8 @@ collation_test_() ->
fun should_collate_with_inclusive_end_rev/1,
fun should_collate_without_inclusive_end_fwd/1,
fun should_collate_without_inclusive_end_rev/1,
- fun should_collate_with_endkey_docid/1
+ fun should_collate_with_endkey_docid/1,
+ fun should_use_collator_for_reduce_grouping/1
]
}
}
@@ -173,6 +175,12 @@ should_collate_with_endkey_docid(Db) ->
?assertEqual(Expect1, Result1)
end).
+should_use_collator_for_reduce_grouping(Db) ->
+ UniqueKeys = lists:usort(fun(A, B) ->
+ not couch_ejson_compare:less_json(B, A)
+ end, ?VALUES),
+ {ok, [{meta,_} | Rows]} = reduce_query(Db, [{group_level, exact}]),
+ ?_assertEqual(length(UniqueKeys), length(Rows)).
make_docs() ->
{Docs, _} = lists:foldl(fun(V, {Docs0, Count}) ->
@@ -194,3 +202,6 @@ rows() ->
run_query(Db, Opts) ->
couch_mrview:query_view(Db, <<"_design/bar">>, <<"zing">>, Opts).
+
+reduce_query(Db, Opts) ->
+ couch_mrview:query_view(Db, <<"_design/red">>, <<"zing">>, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/14f5bba6/test/couch_mrview_red_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_red_views_tests.erl b/test/couch_mrview_red_views_tests.erl
index ae3e454..3100785 100644
--- a/test/couch_mrview_red_views_tests.erl
+++ b/test/couch_mrview_red_views_tests.erl
@@ -92,4 +92,4 @@ should_reduce_with_group_exact(Db) ->
run_query(Db, Opts) ->
- couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).
+ couch_mrview:query_view(Db, <<"_design/red">>, <<"baz">>, Opts).