You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Michael McCaffrey <mm...@ittvis.com> on 2009/11/20 00:15:34 UTC

Erlang views

Playing around with erlang views and I'm trying to spawn the Emit.

 

I see the Emit is defined in couch_native_process but can't get the
spawn to work.

 

Tried spawn(erlang, Emit,["A',"B"]),  spawn(couch_native_process, Emit,
["A","B"]), etc.

 

Get errors like this.

   {badarg,

       [{erlang,spawn,

            [erlang,

             #Fun<couch_native_process.5.68659142>,

             [<<"A">>,<<"B">>]]},

 

Anyone know the proper syntax? 

 

Thanks


Re: Erlang views

Posted by Norman Barker <no...@gmail.com>.
On Friday, November 20, 2009, Paul Davis <pa...@gmail.com> wrote:
> On Thu, Nov 19, 2009 at 6:15 PM, Michael McCaffrey
> <mm...@ittvis.com> wrote:
>> Playing around with erlang views and I'm trying to spawn the Emit.
>>
>>
>>
>> I see the Emit is defined in couch_native_process but can't get the
>> spawn to work.
>>
>>
>>
>> Tried spawn(erlang, Emit,["A',"B"]),  spawn(couch_native_process, Emit,
>> ["A","B"]), etc.
>>
>>
>>
>> Get errors like this.
>>
>>   {badarg,
>>
>>       [{erlang,spawn,
>>
>>            [erlang,
>>
>>             #Fun<couch_native_process.5.68659142>,
>>
>>             [<<"A">>,<<"B">>]]},
>>
>>
>>
>> Anyone know the proper syntax?
>>
>>
>>
>> Thanks
>>
>>
>
> You really shouldn't be spawning here. Unless you pull some acrobatics
> to make sure and block the function and wait for all spawns to return,
> the function calling your views is not setup to expect asynchronous
> results. view functions are expected to behave like functions that are
> passed to lists:fold etc.
>
> HTH,
> Paul Davis
>
if a view is parsing nested json then spawn is useful when traversing
each branch of the json tree. I agree that you need to collect the
results of spawn though and then emit. Being able to do this in
parallel is a nice feature of erlang views.

Norman

Re: Erlang views

Posted by Paul Davis <pa...@gmail.com>.
On Thu, Nov 19, 2009 at 6:15 PM, Michael McCaffrey
<mm...@ittvis.com> wrote:
> Playing around with erlang views and I'm trying to spawn the Emit.
>
>
>
> I see the Emit is defined in couch_native_process but can't get the
> spawn to work.
>
>
>
> Tried spawn(erlang, Emit,["A',"B"]),  spawn(couch_native_process, Emit,
> ["A","B"]), etc.
>
>
>
> Get errors like this.
>
>   {badarg,
>
>       [{erlang,spawn,
>
>            [erlang,
>
>             #Fun<couch_native_process.5.68659142>,
>
>             [<<"A">>,<<"B">>]]},
>
>
>
> Anyone know the proper syntax?
>
>
>
> Thanks
>
>

You really shouldn't be spawning here. Unless you pull some acrobatics
to make sure and block the function and wait for all spawns to return,
the function calling your views is not setup to expect asynchronous
results. view functions are expected to behave like functions that are
passed to lists:fold etc.

HTH,
Paul Davis

Re: Erlang views

Posted by Michael McDaniel <co...@autosys.us>.
 howzabout

        spawn( fun() ->  Emit( Login_name,  [Password] ) end )

 That syntax should be ok though I do not know how it behaves
 within the context of a view.

~M


On Thu, Nov 19, 2009 at 04:59:02PM -0700, Michael McCaffrey wrote:
> Yep, but I've already got the view working and I'm trying to change the
> Emit as follows.
> 
> fun({Doc}) ->
>      Login_name  = proplists:get_value(<<"login_name">>, Doc),
>      Password    = proplists:get_value(<<"password">>, Doc),
>      Emit( Login_name, 
>            [Password])
>  end.
> 
> TO 
> 
> fun({Doc}) ->
>      Login_name  = proplists:get_value(<<"login_name">>, Doc),
>      Password    = proplists:get_value(<<"password">>, Doc),
>      spawn(Emit( Login_name, 
>            [Password]))
>  end.
> 
> Thanks
> 
> -----Original Message-----
> From: Michael [mailto:couchdby@autosys.us] 
> Sent: Thursday, November 19, 2009 4:23 PM
> To: user@couchdb.apache.org
> Subject: Re: Erlang views
> 
> On Thu, Nov 19, 2009 at 04:15:34PM -0700, Michael McCaffrey wrote:
> > Playing around with erlang views and I'm trying to spawn the Emit.
> > 
> >  
> > 
> > I see the Emit is defined in couch_native_process but can't get the
> > spawn to work.
> > 
> >  
> > 
> > Tried spawn(erlang, Emit,["A',"B"]),  spawn(couch_native_process,
> Emit,
> > ["A","B"]), etc.
> > 
> >  
> > 
> > Get errors like this.
> > 
> >    {badarg,
> > 
> >        [{erlang,spawn,
> > 
> >             [erlang,
> > 
> >              #Fun<couch_native_process.5.68659142>,
> > 
> >              [<<"A">>,<<"B">>]]},
> > 
> >  
> > 
> > Anyone know the proper syntax? 
> > 
> >  
> > 
> > Thanks
> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
> 
>  Here is an erlang view as  loaded into Futon using dropdown
>  for Language: erlang, and saved into _design/erlang
> 
>  fun({Doc}) ->
>      Login_name  = proplists:get_value(<<"login_name">>, Doc),
>      Password    = proplists:get_value(<<"password">>, Doc),
>      Emit( Login_name, 
>            [Password])
>  end.
> 
> 
>  If I recall, the example in the couch_native_process.erl file
>  is not quite right.
> 
>  Regarding that file, thanks for the tip o' the hat to erlview.
> 
> ~Michael
> 
> Portland, Oregon, USA
> http://trip.autosys.us
> 

Re: Erlang views

Posted by Adam Kocoloski <ko...@apache.org>.
I guess I have to wonder ... why?  What does spawning buy you here?  Anyway, thy syntax would be

spawn(fun() -> Emit(Login_name, [Password]) end)

Best, Adam

On Nov 19, 2009, at 6:59 PM, Michael McCaffrey wrote:

> Yep, but I've already got the view working and I'm trying to change the
> Emit as follows.
> 
> fun({Doc}) ->
>     Login_name  = proplists:get_value(<<"login_name">>, Doc),
>     Password    = proplists:get_value(<<"password">>, Doc),
>     Emit( Login_name, 
>           [Password])
> end.
> 
> TO 
> 
> fun({Doc}) ->
>     Login_name  = proplists:get_value(<<"login_name">>, Doc),
>     Password    = proplists:get_value(<<"password">>, Doc),
>     spawn(Emit( Login_name, 
>           [Password]))
> end.
> 
> Thanks
> 
> -----Original Message-----
> From: Michael [mailto:couchdby@autosys.us] 
> Sent: Thursday, November 19, 2009 4:23 PM
> To: user@couchdb.apache.org
> Subject: Re: Erlang views
> 
> On Thu, Nov 19, 2009 at 04:15:34PM -0700, Michael McCaffrey wrote:
>> Playing around with erlang views and I'm trying to spawn the Emit.
>> 
>> 
>> 
>> I see the Emit is defined in couch_native_process but can't get the
>> spawn to work.
>> 
>> 
>> 
>> Tried spawn(erlang, Emit,["A',"B"]),  spawn(couch_native_process,
> Emit,
>> ["A","B"]), etc.
>> 
>> 
>> 
>> Get errors like this.
>> 
>>   {badarg,
>> 
>>       [{erlang,spawn,
>> 
>>            [erlang,
>> 
>>             #Fun<couch_native_process.5.68659142>,
>> 
>>             [<<"A">>,<<"B">>]]},
>> 
>> 
>> 
>> Anyone know the proper syntax? 
>> 
>> 
>> 
>> Thanks
> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
> 
> Here is an erlang view as  loaded into Futon using dropdown
> for Language: erlang, and saved into _design/erlang
> 
> fun({Doc}) ->
>     Login_name  = proplists:get_value(<<"login_name">>, Doc),
>     Password    = proplists:get_value(<<"password">>, Doc),
>     Emit( Login_name, 
>           [Password])
> end.
> 
> 
> If I recall, the example in the couch_native_process.erl file
> is not quite right.
> 
> Regarding that file, thanks for the tip o' the hat to erlview.
> 
> ~Michael
> 
> Portland, Oregon, USA
> http://trip.autosys.us
> 


RE: Erlang views

Posted by Michael McCaffrey <mm...@ittvis.com>.
Yep, but I've already got the view working and I'm trying to change the
Emit as follows.

fun({Doc}) ->
     Login_name  = proplists:get_value(<<"login_name">>, Doc),
     Password    = proplists:get_value(<<"password">>, Doc),
     Emit( Login_name, 
           [Password])
 end.

TO 

fun({Doc}) ->
     Login_name  = proplists:get_value(<<"login_name">>, Doc),
     Password    = proplists:get_value(<<"password">>, Doc),
     spawn(Emit( Login_name, 
           [Password]))
 end.

Thanks

-----Original Message-----
From: Michael [mailto:couchdby@autosys.us] 
Sent: Thursday, November 19, 2009 4:23 PM
To: user@couchdb.apache.org
Subject: Re: Erlang views

On Thu, Nov 19, 2009 at 04:15:34PM -0700, Michael McCaffrey wrote:
> Playing around with erlang views and I'm trying to spawn the Emit.
> 
>  
> 
> I see the Emit is defined in couch_native_process but can't get the
> spawn to work.
> 
>  
> 
> Tried spawn(erlang, Emit,["A',"B"]),  spawn(couch_native_process,
Emit,
> ["A","B"]), etc.
> 
>  
> 
> Get errors like this.
> 
>    {badarg,
> 
>        [{erlang,spawn,
> 
>             [erlang,
> 
>              #Fun<couch_native_process.5.68659142>,
> 
>              [<<"A">>,<<"B">>]]},
> 
>  
> 
> Anyone know the proper syntax? 
> 
>  
> 
> Thanks
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 

 Here is an erlang view as  loaded into Futon using dropdown
 for Language: erlang, and saved into _design/erlang

 fun({Doc}) ->
     Login_name  = proplists:get_value(<<"login_name">>, Doc),
     Password    = proplists:get_value(<<"password">>, Doc),
     Emit( Login_name, 
           [Password])
 end.


 If I recall, the example in the couch_native_process.erl file
 is not quite right.

 Regarding that file, thanks for the tip o' the hat to erlview.

~Michael

Portland, Oregon, USA
http://trip.autosys.us


Re: Erlang views

Posted by Michael <co...@autosys.us>.
On Thu, Nov 19, 2009 at 04:15:34PM -0700, Michael McCaffrey wrote:
> Playing around with erlang views and I'm trying to spawn the Emit.
> 
>  
> 
> I see the Emit is defined in couch_native_process but can't get the
> spawn to work.
> 
>  
> 
> Tried spawn(erlang, Emit,["A',"B"]),  spawn(couch_native_process, Emit,
> ["A","B"]), etc.
> 
>  
> 
> Get errors like this.
> 
>    {badarg,
> 
>        [{erlang,spawn,
> 
>             [erlang,
> 
>              #Fun<couch_native_process.5.68659142>,
> 
>              [<<"A">>,<<"B">>]]},
> 
>  
> 
> Anyone know the proper syntax? 
> 
>  
> 
> Thanks
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 

 Here is an erlang view as  loaded into Futon using dropdown
 for Language: erlang, and saved into _design/erlang

 fun({Doc}) ->
     Login_name  = proplists:get_value(<<"login_name">>, Doc),
     Password    = proplists:get_value(<<"password">>, Doc),
     Emit( Login_name, 
           [Password])
 end.


 If I recall, the example in the couch_native_process.erl file
 is not quite right.

 Regarding that file, thanks for the tip o' the hat to erlview.

~Michael

Portland, Oregon, USA
http://trip.autosys.us