Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Support additional doc option opts in views#52

Open
b20n wants to merge 1 commit intoapache:masterfrom
b20n:parse-more-doc-opts-in-views
Open

Support additional doc option opts in views#52
b20n wants to merge 1 commit intoapache:masterfrom
b20n:parse-more-doc-opts-in-views

Conversation

@b20n
Copy link
Contributor

@b20n b20n commented Jul 17, 2016

COUCHDB-2568 allowed several attachment-related doc open options to be
passed through _all_docs queries. This patch extends that work to
various other options by adding support for various doc open options to
the view argument parser:

  • revs_info
  • deleted_conflicts
  • meta
  • r

Additionally, this patch changes the behavior of the "conflicts" view
option to furthermore apply the "conflicts" doc open option if
include_docs=true is specified by the user.

Without this functionality there is no way for a user to implement an
"always on" conflict detection and resolution policy if they're using
_all_docs POST queries as their primary document access path.

COUCHDB-3064

COUCHDB-2568 allowed several attachment-related doc open options to be
passed through _all_docs queries. This patch extends that work to
various other options by adding support for various doc open options to
the view argument parser:

- revs_info
- deleted_conflicts
- meta
- r

Additionally, this patch changes the behavior of the "conflicts" view
option to furthermore apply the "conflicts" doc open option if
include_docs=true is specified by the user.

Without this functionality there is no way for a user to implement an
"always on" conflict detection and resolution policy if they're using
_all_docs POST queries as their primary document access path.

COUCHDB-3064
@chewbranca
Copy link
Contributor

@banjiewen you'll want to add validations for these new arguments in

validate_args(Args) ->
GroupLevel = determine_group_level(Args),
Reduce = Args#mrargs.reduce,
case Reduce == undefined orelse is_boolean(Reduce) of
true -> ok;
_ -> mrverror(<<"Invalid `reduce` value.">>)
end,
case {Args#mrargs.view_type, Reduce} of
{map, true} -> mrverror(<<"Reduce is invalid for map-only views.">>);
_ -> ok
end,
case {Args#mrargs.view_type, GroupLevel, Args#mrargs.keys} of
{red, exact, _} -> ok;
{red, _, KeyList} when is_list(KeyList) ->
Msg = <<"Multi-key fetchs for reduce views must use `group=true`">>,
mrverror(Msg);
_ -> ok
end,
case Args#mrargs.keys of
Keys when is_list(Keys) -> ok;
undefined -> ok;
_ -> mrverror(<<"`keys` must be an array of strings.">>)
end,
case {Args#mrargs.keys, Args#mrargs.start_key,
Args#mrargs.end_key} of
{undefined, _, _} -> ok;
{[], _, _} -> ok;
{[_|_], undefined, undefined} -> ok;
_ -> mrverror(<<"`keys` is incompatible with `key`"
", `start_key` and `end_key`">>)
end,
case Args#mrargs.start_key_docid of
undefined -> ok;
SKDocId0 when is_binary(SKDocId0) -> ok;
_ -> mrverror(<<"`start_key_docid` must be a string.">>)
end,
case Args#mrargs.end_key_docid of
undefined -> ok;
EKDocId0 when is_binary(EKDocId0) -> ok;
_ -> mrverror(<<"`end_key_docid` must be a string.">>)
end,
case Args#mrargs.direction of
fwd -> ok;
rev -> ok;
_ -> mrverror(<<"Invalid direction.">>)
end,
case {Args#mrargs.limit >= 0, Args#mrargs.limit == undefined} of
{true, _} -> ok;
{_, true} -> ok;
_ -> mrverror(<<"`limit` must be a positive integer.">>)
end,
case Args#mrargs.skip < 0 of
true -> mrverror(<<"`skip` must be >= 0">>);
_ -> ok
end,
case {Args#mrargs.view_type, GroupLevel} of
{red, exact} -> ok;
{_, 0} -> ok;
{red, Int} when is_integer(Int), Int >= 0 -> ok;
{red, _} -> mrverror(<<"`group_level` must be >= 0">>);
{map, _} -> mrverror(<<"Invalid use of grouping on a map view.">>)
end,
case Args#mrargs.stale of
ok -> ok;
update_after -> ok;
false -> ok;
_ -> mrverror(<<"Invalid value for `stale`.">>)
end,
case is_boolean(Args#mrargs.inclusive_end) of
true -> ok;
_ -> mrverror(<<"Invalid value for `inclusive_end`.">>)
end,
case {Args#mrargs.view_type, Args#mrargs.include_docs} of
{red, true} -> mrverror(<<"`include_docs` is invalid for reduce">>);
{_, ID} when is_boolean(ID) -> ok;
_ -> mrverror(<<"Invalid value for `include_docs`">>)
end,
case {Args#mrargs.view_type, Args#mrargs.conflicts} of
{_, undefined} -> ok;
{map, V} when is_boolean(V) -> ok;
{red, undefined} -> ok;
{map, _} -> mrverror(<<"Invalid value for `conflicts`.">>);
{red, _} -> mrverror(<<"`conflicts` is invalid for reduce views.">>)
end,
SKDocId = case {Args#mrargs.direction, Args#mrargs.start_key_docid} of
{fwd, undefined} -> <<>>;
{rev, undefined} -> <<255>>;
{_, SKDocId1} -> SKDocId1
end,
EKDocId = case {Args#mrargs.direction, Args#mrargs.end_key_docid} of
{fwd, undefined} -> <<255>>;
{rev, undefined} -> <<>>;
{_, EKDocId1} -> EKDocId1
end,
case is_boolean(Args#mrargs.sorted) of
true -> ok;
_ -> mrverror(<<"Invalid value for `sorted`.">>)
end,
Args#mrargs{
start_key_docid=SKDocId,
end_key_docid=EKDocId,
group_level=GroupLevel
}.

@b20n
Copy link
Contributor Author

b20n commented Jul 27, 2016

you'll want to add validations for these new arguments

These all end up in #mrargs.doc_options, which isn't validated there. I'm not sure it's validated anywhere, to be honest.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments