You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by nickva <gi...@git.apache.org> on 2015/09/23 20:32:22 UTC

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

GitHub user nickva opened a pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/30

    Fix validation of query design documents

    Jira: COUCHDB-2818
    
    If language is "query" then map functions will be objects.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nickva/couchdb-couch-mrview 2818-fix-validation-for-queries

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-couch-mrview/pull/30.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #30
    
----
commit 5f28457d62f0b4451e21034429d0a0d434f89b0a
Author: Nick Vatamaniuc <va...@gmail.com>
Date:   2015-09-23T18:30:22Z

    Fix validation of query design documents
    
    Jira: COUCHDB-2818
    
    If language is "query" then map functions will be objects.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/30#discussion_r40327011
  
    --- Diff: src/couch_mrview.erl ---
    @@ -52,24 +52,31 @@
     %% In the most common case name is the view name and
     %% value is an object that must have a "map" function,
     %% and an optional "reduce" function. "map" and "reduce"
    -%% values should be strings (function contents).
    +%% values should be strings (function contents), except
    +%% in case when langauge is <<query>> then maps must
    +%% be objects.
     %%
     %% "lib" is a special case. The value
     %% of "lib" is an object that will contain libary code
     %% so it not validated.
     %%
    -validate_view(<<"lib">>, {_Libs})->
    +validate_view(<<"lib">>, {_Libs}, _)->
         ok;
    -validate_view(VName, {Views}) ->
    -    case couch_util:get_value(<<"map">>, Views) of
    -        MapVal when is_binary(MapVal) ->
    +validate_view(VName, {Views}, Language) ->
    +    case {couch_util:get_value(<<"map">>, Views), Language}  of
    +        {{[_ | _]}, <<"query">>} ->
                 ok;
    -        undefined ->
    +        {Mapval, Lang} when is_binary(Mapval) andalso Lang =/= <<"query">> ->
    --- End diff --
    
    hrm, can we instead have a `{_, <<"query">>}` clause that throws? It keeps the "query" logic to two neat clauses that way.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/30#discussion_r40326693
  
    --- Diff: test/couch_mrview_ddoc_validation_tests.erl ---
    @@ -363,3 +365,32 @@ should_accept_any_in_lib(Db) ->
                            ]}}
         ]}),
         ?_assertMatch({ok,_}, couch_db:update_doc(Db, Doc, [])).
    +
    +
    +
    +should_accept_map_object_for_queries(Db) ->
    +    Doc = couch_doc:from_json_obj({[
    +        {<<"_id">>, <<"_design/should_accept_map_objects_for_queries">>},
    +        {<<"language">>, <<"query">>},
    +        {<<"views">>, {[
    +                         {<<"view1">>, {[
    --- End diff --
    
    indentation should be 4 spaces.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/30#discussion_r40327263
  
    --- Diff: src/couch_mrview.erl ---
    @@ -52,24 +52,31 @@
     %% In the most common case name is the view name and
     %% value is an object that must have a "map" function,
     %% and an optional "reduce" function. "map" and "reduce"
    -%% values should be strings (function contents).
    +%% values should be strings (function contents), except
    +%% in case when langauge is <<query>> then maps must
    +%% be objects.
     %%
     %% "lib" is a special case. The value
     %% of "lib" is an object that will contain libary code
     %% so it not validated.
     %%
    -validate_view(<<"lib">>, {_Libs})->
    +validate_view(<<"lib">>, {_Libs}, _)->
    --- End diff --
    
    say `_Language` for clarity.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/30#discussion_r40327447
  
    --- Diff: src/couch_mrview.erl ---
    @@ -99,17 +106,17 @@ validate_view(VName, _) ->
     %%  - views :  Validated by a special function.
     %%  - options : Allowed to contain non-string values.
     %%
    -validate_opt_object(<<"views">>, {Views})->
    -    [validate_view(VName, ViewObj) || {VName, ViewObj} <- Views],
    +validate_opt_object(<<"views">>, {Views}, Language)->
    +    [validate_view(VName, ViewObj, Language) || {VName, ViewObj} <- Views],
         ok;
    -validate_opt_object(<<"options">>, {_})->
    +validate_opt_object(<<"options">>, {_}, _)->
    --- End diff --
    
    `_Language` throughout pls.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/couchdb-couch-mrview/pull/30


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/30#issuecomment-142957708
  
    +1


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request: Fix validation of query design ...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/30#discussion_r40327147
  
    --- Diff: src/couch_mrview.erl ---
    @@ -52,24 +52,31 @@
     %% In the most common case name is the view name and
     %% value is an object that must have a "map" function,
     %% and an optional "reduce" function. "map" and "reduce"
    -%% values should be strings (function contents).
    +%% values should be strings (function contents), except
    +%% in case when langauge is <<query>> then maps must
    +%% be objects.
     %%
     %% "lib" is a special case. The value
     %% of "lib" is an object that will contain libary code
     %% so it not validated.
     %%
    -validate_view(<<"lib">>, {_Libs})->
    +validate_view(<<"lib">>, {_Libs}, _)->
         ok;
    -validate_view(VName, {Views}) ->
    -    case couch_util:get_value(<<"map">>, Views) of
    -        MapVal when is_binary(MapVal) ->
    +validate_view(VName, {Views}, Language) ->
    +    case {couch_util:get_value(<<"map">>, Views), Language}  of
    +        {{[_ | _]}, <<"query">>} ->
                 ok;
    -        undefined ->
    +        {Mapval, Lang} when is_binary(Mapval) andalso Lang =/= <<"query">> ->
    +            ok;
    +        {undefined, _} ->
                 Err0 = <<"View ",VName/binary, " must have a map function">>,
                 throw ({invalid_design_doc, Err0});
    -        _ ->
    -            Err1 = <<"`map` in ", VName/binary, " must be a string">>,
    -            throw({invalid_design_doc, Err1})
    +        {_, <<"query">>} ->
    --- End diff --
    
    aha, well, I think just pull this one up to be the second clause and we can drop the `andalso Lang =/= <<"query">>` bit?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---