diff options
author | Robert Newson <rnewson@apache.org> | 2018-08-06 18:18:33 +0100 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2018-09-03 17:43:00 +0100 |
commit | 8ee83a873fe5b9b7666786819335996effcd11fd (patch) | |
tree | 3f1039efcb0fc9b0d500ffa471c3ff145d9abcb1 | |
parent | 1cbc8f07f1114988e5a30bd9537543d464e0a1ad (diff) | |
download | couchdb-8ee83a873fe5b9b7666786819335996effcd11fd.tar.gz |
Allow partitioned option in mrviews
Default to database's partitioned setting if not present in ddoc.
-rw-r--r-- | src/chttpd/src/chttpd_db.erl | 4 | ||||
-rw-r--r-- | src/couch_mrview/src/couch_mrview.erl | 5 | ||||
-rw-r--r-- | src/couch_mrview/src/couch_mrview_http.erl | 9 | ||||
-rw-r--r-- | src/couch_mrview/src/couch_mrview_index.erl | 4 | ||||
-rw-r--r-- | src/couch_mrview/src/couch_mrview_util.erl | 14 |
5 files changed, 31 insertions, 5 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl index 820e19144..c8a10d322 100644 --- a/src/chttpd/src/chttpd_db.erl +++ b/src/chttpd/src/chttpd_db.erl @@ -1607,8 +1607,8 @@ set_namespace(<<"_local_docs">>, Args) -> set_namespace(<<"_local">>, Args); set_namespace(<<"_design_docs">>, Args) -> set_namespace(<<"_design">>, Args); -set_namespace(NS, #mrargs{extra = Extra} = Args) -> - Args#mrargs{extra = [{namespace, NS} | Extra]}. +set_namespace(NS, #mrargs{} = Args) -> + couch_mrview_util:set_extra(Args, namespace, NS). %% /db/_bulk_get stuff diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl index 533dd2de9..db467f081 100644 --- a/src/couch_mrview/src/couch_mrview.erl +++ b/src/couch_mrview/src/couch_mrview.erl @@ -57,6 +57,9 @@ validate_ddoc_fields(DDoc) -> [{<<"language">>, string}], [{<<"lists">>, object}, {any, [object, string]}], [{<<"options">>, object}], + [{<<"options">>, object}, {<<"include_design">>, boolean}], + [{<<"options">>, object}, {<<"partitioned">>, boolean}], + [{<<"options">>, object}, {<<"local_seq">>, boolean}], [{<<"rewrites">>, [string, array]}], [{<<"shows">>, object}, {any, [object, string]}], [{<<"updates">>, object}, {any, [object, string]}], @@ -133,6 +136,8 @@ validate_ddoc_field(Value, array) when is_list(Value) -> ok; validate_ddoc_field({Value}, object) when is_list(Value) -> ok; +validate_ddoc_field(Value, boolean) when is_boolean(Value) -> + ok; validate_ddoc_field({Props}, {any, Type}) -> validate_ddoc_field1(Props, Type); validate_ddoc_field({Props}, {Key, Type}) -> diff --git a/src/couch_mrview/src/couch_mrview_http.erl b/src/couch_mrview/src/couch_mrview_http.erl index 004caef09..dfdb6449a 100644 --- a/src/couch_mrview/src/couch_mrview_http.erl +++ b/src/couch_mrview/src/couch_mrview_http.erl @@ -461,8 +461,10 @@ row_to_json(Id0, Row) -> ?JSON_ENCODE(Obj). -parse_params(#httpd{}=Req, Keys) -> - parse_params(chttpd:qs(Req), Keys); +parse_params(#httpd{path_parts=[DbName | _]}=Req, Keys) -> + Args = parse_params(chttpd:qs(Req), Keys), + Partitioned = mem3:is_partitioned(DbName), + couch_mrview_util:set_extra(Args, partitioned, Partitioned); parse_params(Props, Keys) -> Args = #mrargs{}, parse_params(Props, Keys, Args). @@ -582,6 +584,9 @@ parse_param(Key, Val, Args, IsDecoded) -> Args#mrargs{callback=couch_util:to_binary(Val)}; "sorted" -> Args#mrargs{sorted=parse_boolean(Val)}; + "partition" -> + Partition = couch_util:to_binary(Val), + couch_mrview_util:set_extra(Args, partition, Partition); _ -> BKey = couch_util:to_binary(Key), BVal = couch_util:to_binary(Val), diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl index 5d285d639..2d462d954 100644 --- a/src/couch_mrview/src/couch_mrview_index.erl +++ b/src/couch_mrview/src/couch_mrview_index.erl @@ -38,10 +38,12 @@ get(update_options, #mrst{design_opts = Opts}) -> LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false), SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false), KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false), + Partitioned = couch_util:get_value(<<"partitioned">>, Opts, false), if IncDesign -> [include_design]; true -> [] end ++ if LocalSeq -> [local_seq]; true -> [] end ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end - ++ if SeqIndexed -> [seq_indexed]; true -> [] end; + ++ if SeqIndexed -> [seq_indexed]; true -> [] end + ++ if Partitioned -> [partitioned]; true -> [] end; get(fd, #mrst{fd = Fd}) -> Fd; get(language, #mrst{language = Language}) -> diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl index 120a9b873..a63701f8f 100644 --- a/src/couch_mrview/src/couch_mrview_util.erl +++ b/src/couch_mrview/src/couch_mrview_util.erl @@ -30,6 +30,7 @@ -export([extract_view/4, extract_view_reduce/1]). -export([get_view_keys/1, get_view_queries/1]). -export([set_view_type/3]). +-export([set_extra/3, get_extra/2, get_extra/3]). -export([changes_key_opts/2]). -export([fold_changes/4]). -export([to_key_seq/1]). @@ -178,6 +179,19 @@ set_view_type(Args, ViewName, [View | Rest]) -> end. +set_extra(#mrargs{} = Args, Key, Value) -> + Extra0 = Args#mrargs.extra, + Extra1 = lists:ukeysort(1, [{Key, Value} | Extra0]), + Args#mrargs{extra = Extra1}. + + +get_extra(#mrargs{} = Args, Key) -> + couch_util:get_value(Key, Args#mrargs.extra). + +get_extra(#mrargs{} = Args, Key, Default) -> + couch_util:get_value(Key, Args#mrargs.extra, Default). + + extract_view(_Lang, _Args, _ViewName, []) -> throw({not_found, missing_named_view}); extract_view(Lang, #mrargs{view_type=map}=Args, Name, [View | Rest]) -> |