incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j.kalsb...@jk-itberatung.de
Subject Re: Strange behaviour with Erlang views
Date Thu, 20 Jan 2011 15:16:18 GMT
Hi,

thanks for your support. This really led me into the right direction.  
And sorry for posting dumb rookie questions.

The reduce function (aka group by) is:
fun(Keys, Values,ReReduce) ->
	if ReReduce ->
		lists:sum(Values);
	true ->
		length(Values)
	end
	end.

and works fine

BR,

J
Zitat von Robert Newson <robert.newson@gmail.com>:

> You want;
>
> fun(Keys, Values,ReReduce) ->  if true -> 17 end end.
>
> You didn't end your if statement, basically.
>
> B.
>
> On Thu, Jan 20, 2011 at 12:22 PM, Filipe David Manana
> <fdmanana@apache.org> wrote:
>> This:
>>
>> fun(Keys, Values,ReReduce) ->  if true -> 17 end.
>>
>> is invalid Erlang.
>>
>> Have you tried it an Erlang shell?
>> You miss the "else" clause likely. Look at section 7.7 of
>> http://www.erlang.org/doc/reference_manual/expressions.html
>>
>> Anyway that logic it seems you always want to return the integer 17.
>>
>>
>>
>> On Thu, Jan 20, 2011 at 11:40 AM,  <j.kalsbach@jk-itberatung.de> wrote:
>>>
>>> Hi all, I've got a strange problem with Erlang views. I've got a simple and
>>> useless reduce function which works as expected:
>>> fun(Keys, Values,ReReduce) ->  17 end.
>>> Now I change it to another simple and useless function:
>>> fun(Keys, Values,ReReduce) ->  if true -> 17 end.
>>> The function compiles fine with plain Erlang.
>>> CouchDB complains.
>>> Couch.log:
>>> ...
>>> [{view,0,
>>>                             [<<"_temp">>],
>>>                             <<"\n%% Map Function\nfun({Doc})
->\n
>>>  <<K,_/binary>> = proplists:get_value(<<\"_rev\">>,
Doc, null),\n  V =
>>> proplists:get_value(<<\"_id\">>, Doc, null),\n  Emit(<<K>>,
 
>>> V)\nend.\n\n">>,
>>>                             nil,
>>>                             [{<<"_temp">>,
>>>                               <<"fun(Keys, Values,ReReduce)
->  if true ->
>>> 17 end.">>}],
>>>                             []}]
>>> ...
>>> ** Reason for termination ==
>>> ** {{try_clause,[<<"error">>,<<"native_query_server">>,
>>>                 <<"couch native server error: {1,erl_parse,[\"syntax
error
>>> before: \",\"'.'\"]}">>]},
>>>    [{couch_query_servers,os_reduce,3},
>>>     {couch_query_servers,reduce,3},
>>>     {couch_view_group,'-init_group/4-fun-0-',4},
>>>     {couch_btree,'-write_node/3-lc$^0/1-0-',3},
>>>     {couch_btree,write_node,3},
>>>     {couch_btree,modify_node,4},
>>>     {couch_btree,query_modify,4},
>>>     {couch_btree,add_remove,3}]}
>>>
>>> It seems that the native_query_server has problems with valid syntax.
>>> Originally I wanted to write a group by function where I need if or case to
>>> react on ReReduce or not.
>>> Does anyone has an idea what went wrong?
>>>
>>> Many thanks in advance,
>>>
>>> Jörg
>>>
>>>
>>
>>
>>
>> --
>> Filipe David Manana,
>> fdmanana@gmail.com, fdmanana@apache.org
>>
>> "Reasonable men adapt themselves to the world.
>>  Unreasonable men adapt the world to themselves.
>>  That's why all progress depends on unreasonable men."
>>
>





Mime
View raw message