You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Alexander Kuleshov <ak...@tpip.net> on 2013/06/27 16:38:04 UTC

{case_clause,{error,[],function_clause}} in CouchDb-1.2.0

Hello,

I'm trying to use Couchdb-1.2.0 with Couchbeam.

I create database, documents and etc...

I have a view:

{
   "_id": "_design/task",
   "_rev": "1-0ba3c64c158deb66749cf23aaee9e855",
   "language": "erlang",
   "views": {
       "by_task_creation": {
           "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n",
           "reduce": "fun(_Keys, Values, false) -> length(Values);\n   (_Keys, Values, true)  -> lists:sum(Values) end.\n"
       },
       "by_task_selector": {
           "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n"
       }
   }
}

But when i'm trying to fetch it i got error:

{case_clause,{error,[],function_clause}}

I'm trying with: couchbeam_view:fetch(DB, {<<"_design/task">>, <<"by_task_creation">>}, [{reduce, true}]) 

How can i make it correctly?

Thank you.

Отв.: Re: {case_clause,{error,[],function_clause}} in CouchDb-1.2.0

Posted by Alexander Kuleshov <ak...@tpip.net>.
Hello,

Thank for your replies.

Now i'm trying to request with curl and it seems to works:

curl -X GET http://localhost:5984/xray/_design/task/_view/by_task_creation/?reduce=true

{"rows":[]}

How can i make the same request with couchbeam?

Thank you

Re: {case_clause,{error,[],function_clause}} in CouchDb-1.2.0

Posted by Benoit Chesneau <bc...@gmail.com>.
On Thu, Jun 27, 2013 at 4:38 PM, Alexander Kuleshov <ak...@tpip.net> wrote:
> Hello,
>
> I'm trying to use Couchdb-1.2.0 with Couchbeam.
>
> I create database, documents and etc...
>
> I have a view:
>
> {
>    "_id": "_design/task",
>    "_rev": "1-0ba3c64c158deb66749cf23aaee9e855",
>    "language": "erlang",
>    "views": {
>        "by_task_creation": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n",
>            "reduce": "fun(_Keys, Values, false) -> length(Values);\n   (_Keys, Values, true)  -> lists:sum(Values) end.\n"
>        },
>        "by_task_selector": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n"
>        }
>    }
> }
>
> But when i'm trying to fetch it i got error:
>
> {case_clause,{error,[],function_clause}}
>
> I'm trying with: couchbeam_view:fetch(DB, {<<"_design/task">>, <<"by_task_creation">>}, [{reduce, true}])
>
> How can i make it correctly?
>
> Thank you.


Do you have the full trace from couchdb?

- benoit

Re: {case_clause,{error,[],function_clause}} in CouchDb-1.2.0

Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 27 June 2013 16:38, Alexander Kuleshov <ak...@tpip.net> wrote:
> Hello,
>
> I'm trying to use Couchdb-1.2.0 with Couchbeam.
>
> I create database, documents and etc...
>
> I have a view:
>
> {
>    "_id": "_design/task",
>    "_rev": "1-0ba3c64c158deb66749cf23aaee9e855",
>    "language": "erlang",
>    "views": {
>        "by_task_creation": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n",
>            "reduce": "fun(_Keys, Values, false) -> length(Values);\n   (_Keys, Values, true)  -> lists:sum(Values) end.\n"
>        },
>        "by_task_selector": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n"
>        }
>    }
> }
>
> But when i'm trying to fetch it i got error:
>
> {case_clause,{error,[],function_clause}}
>
> I'm trying with: couchbeam_view:fetch(DB, {<<"_design/task">>, <<"by_task_creation">>}, [{reduce, true}])
>
> How can i make it correctly?
>
> Thank you.

case_clause is a runtime error telling you that your erlang function
doesn't match all cases encountered.  Add a default case in and you
should be fine. I'm not trying to decipher the
\n\t\tunread\table\n\t\tcontent above but if you start couchdb in
interactive mode `couchdb -i` then you can test stuff in the shell
very easily:

where you'll need to update the "…" stuff obviously.

rr("/repos/couch/git/src/couchdb/*.hrl").
rr("/repos/couch/git/src/couch_mrview/include/*.hrl").
{ok, Db} = couch_db:open_int(<<"somedb">>, []).
{ok, Doc} = couch_db:open_doc(Db, <<"somedocid">>).
Body = couch_doc:with_ejson_body(Doc). may also be useful.

and then call your fun on these docs to see what's happening.

If you `couch_config:set("log","level","debug").` prior to triggering
a view rebuild, you will probably see what doc this is failing on in
the logs. Most commonly people forget that databases contain ddocs and
don't account for that in the view.

A+
Dave

Re: {case_clause,{error,[],function_clause}} in CouchDb-1.2.0

Posted by Alexander Shorin <kx...@gmail.com>.
Hi Alexander,

Does curl request to this view with same query parameters works?
--
,,,^..^,,,


On Thu, Jun 27, 2013 at 6:38 PM, Alexander Kuleshov <ak...@tpip.net> wrote:
> Hello,
>
> I'm trying to use Couchdb-1.2.0 with Couchbeam.
>
> I create database, documents and etc...
>
> I have a view:
>
> {
>    "_id": "_design/task",
>    "_rev": "1-0ba3c64c158deb66749cf23aaee9e855",
>    "language": "erlang",
>    "views": {
>        "by_task_creation": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n",
>            "reduce": "fun(_Keys, Values, false) -> length(Values);\n   (_Keys, Values, true)  -> lists:sum(Values) end.\n"
>        },
>        "by_task_selector": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>, Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>, Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t    _ -> ok\n\tend\nend.\n"
>        }
>    }
> }
>
> But when i'm trying to fetch it i got error:
>
> {case_clause,{error,[],function_clause}}
>
> I'm trying with: couchbeam_view:fetch(DB, {<<"_design/task">>, <<"by_task_creation">>}, [{reduce, true}])
>
> How can i make it correctly?
>
> Thank you.