incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <jch...@apache.org>
Subject Re: Thoughts on document/views...
Date Wed, 11 Feb 2009 23:28:40 GMT
On Wed, Feb 11, 2009 at 2:21 PM, Michael McDaniel <couchdb@autosys.us> wrote:
> On Thu, Feb 12, 2009 at 07:30:17AM +1030, Antony Blakey wrote:
>>
>> On 12/02/2009, at 7:27 AM, Antony Blakey wrote:
>>
>>> That guard could be an erlang function, defined in the design doc.
>>
>> And an obvious extension is to allow view functions to be written in
>> erlang - no JSON conversion, no external.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>  I am working on an Erlang view server (EVS).  It currently works
>  in a rudimentary fashion.  I have been testing from Futon.  I do
>  not think it is currently as flexible as the default javascript map
>  funs, though do not know all the map fun capabilities available with
>  the default.
>
>
>  The only CDB changes I have needed are to add the following two
>  functions to couch_query_servers.erl  (valid as of CDB v740870)
>  before their respective existing funs.
>
>  The start_doc_map/2 fun is different only in that it provides EVS
>  Pid rather than using get_os_process(Lang).  Because the EVS is
>  started as a daemon and not like main.js is started,
>  get_os_process(Lang) does not work as written.
>
>
>  The map_docs/2 fun is different in that no JSON <-> Erlang term()
>  conversion is done (not needed when talking Erlang <-> Erlang).
>
>
>
> start_doc_map(<<"erlang">>, Functions) ->
>  Pid = erlang:whereis(erlview) ,   % need to parameterize erlview
>                                    % Pid is fed to map_docs
>    lists:foreach(fun(FunctionSource) ->
>                      true = couch_os_process:prompt(Pid,
>                                                    [<<"add_fun">>,
>                                                     FunctionSource])
>                  end, Functions),
>    {ok, {<<"erlang">>, Pid}}
> ;
>
>
>
> % Pid comes from start_doc_map/2 (see call in couch_view_updater)
> map_docs({<<"erlang">>, Pid}, Docs) ->
>    Results = lists:map( fun( Doc ) ->
>                           couch_os_process:prompt(Pid, [<<"map_doc">>, Doc])
>                         end,
>                         Docs) ,
>    {ok, Results}
> ;
>
>
>
> NOTE that the additional start_doc_map/2 fun can be eliminated if you
> want to change get_os_process/1 to ...
>
> get_os_process(Lang) ->
>   case Lang
>     of <<"erlang">> -> erlang:whereis(erlview) ;
>     _               -> gen_server:call(couch_query_servers,
>                                       {get_proc, Lang})
>   end
> .
>
>
>  Also note that, obviously, the EVS name 'erlview' is hard-coded and
>  should be a local.ini parameter.
>
>
>  Above is a first-cut; possibly a message passing protocol to the
>  EVS would be faster though that would require more CDB hacking.
>
>
>  I'll post some code when it does a bit more than gurgle bubbles.
>
>
>  Please, if there is some activity to change CDB internals to
>  simplify a native Erlang view server or create a more direct
>  interface, let me know so I don't go too far down this road.
>
>  No sense replicating effort (only databases!).
>
> ~Michael
>

We've got a thread going on dev@ about this, so anyone who's ears just
perked up should check it out:

http://mail-archives.apache.org/mod_mbox/couchdb-dev/200902.mbox/%3ce282921e0902101229m783671a8w5efd3b5badf4fe3e@mail.gmail.com%3e

-- 
Chris Anderson
http://jchris.mfdz.com

Mime
View raw message