Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 14312 invoked from network); 11 Feb 2009 22:22:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Feb 2009 22:22:21 -0000 Received: (qmail 29328 invoked by uid 500); 11 Feb 2009 22:22:19 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 29293 invoked by uid 500); 11 Feb 2009 22:22:19 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 29282 invoked by uid 99); 11 Feb 2009 22:22:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Feb 2009 14:22:19 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of couchdb@autosys.us designates 216.99.218.149 as permitted sender) Received: from [216.99.218.149] (HELO delora.autosys.us) (216.99.218.149) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Feb 2009 22:22:10 +0000 Received: by delora.autosys.us (Postfix, from userid 1000) id DF57125C893; Wed, 11 Feb 2009 14:21:48 -0800 (PST) Date: Wed, 11 Feb 2009 14:21:48 -0800 From: Michael McDaniel To: user@couchdb.apache.org Subject: Re: Thoughts on document/views... Message-ID: <20090211222148.GD22018@delora.autosys.us> Mail-Followup-To: user@couchdb.apache.org References: <7db9abd30902111022i6c7f6385n23beba458565afb@mail.gmail.com> <7db9abd30902111053h7bdac9fcn9e45da6f597b0a90@mail.gmail.com> <8ED9ACCA-A828-498F-8A1E-26CFC077AF35@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8ED9ACCA-A828-498F-8A1E-26CFC077AF35@gmail.com> Organization: http://autosys.us User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Virus-Checked: Checked by ClamAV on apache.org 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 > > Antony Blakey > ------------- > CTO, Linkuistics Pty Ltd > Ph: 0438 840 787 > > One should respect public opinion insofar as is necessary to avoid > starvation and keep out of prison, but anything that goes beyond this is > voluntary submission to an unnecessary tyranny. > -- Bertrand Russell > > -- Michael McDaniel Portland, Oregon, USA http://trip.autosys.us http://autosys.us