couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paweł Stawicki <pawelstawi...@gmail.com>
Subject Re: some guidance for couchdb views
Date Sat, 26 Dec 2009 17:12:02 GMT
On Sat, Dec 26, 2009 at 15:05, Fink Mark <mark@mark-fink.de> wrote:
> Hi there,
>
> I am new to couchdb and currently stuck with the sample app I am working on.
>
> I managed to put some data into couchdb, for example:
> File    CountLineCode    SumCyclomatic    RatioCommentToCode
> content/events/src/nsQueryContentEventHandler.cpp    432    226    0.12
> content/events/src/nsXMLEventsElement.cpp    47    11    0.79
> content/events/src/nsXMLEventsManager.cpp    352    94    0.15
> content/html/content/src/nsClientRect.cpp    82    35    0.48
> content/html/content/src/nsFormSubmission.cpp    813    187    0.49
> content/html/content/src/nsGenericHTMLElement.cpp    2652    646    0.13
> content/html/content/src/nsHTMLAnchorElement.cpp    456    132    0.18
> content/html/content/src/nsHTMLAreaElement.cpp    365    101    0.16
> content/html/content/src/nsHTMLAudioElement.cpp    43    26    1.02
> (every row is put into its own document)
>
> Now I want to query the datastore using map/reduce views. The reduce
> function should add the values for a given key (keys are part of the file
> value). For example a query for
> "content/html/content/src/nsFormSubmission.cpp" would result into
> "CountLineCode":  813, "SumCyclomatic":  187, "RatioCommentToCode": 0.4. A
> query for "content/html/" would add the values where File matches the given
> prefix. "content/" would add more and "" would add the values of all
> documents.
>
> I feel that this is exactly what couchdb is good at and I think there is a
> very simple solution to this. Unfortunately I do not have much practise with
> the map reduce functions and I need some help. Maybe there is tutorial
> available to help with similar path oriented views?
>
> Maybe I got it all wrong and should put all the lines above into one single
> document. I had this before but futon stopped working nicely because the
> document had about 5000 lines. I think in this scenario I could not even
> apply the map reduce functions. I have to traverse the document by myself.
> What do you think?

I think putting all the lines into one document is not a good idea.

For grouping values as you want, you need to use multiple key. E.g.
record for this line:
content/events/src/nsXMLEventsManager.cpp    352    94    0.15

should have multi-key:
["content", "events", "src", "nsXMLEventsManager.cpp"]
and values:
352, 94, 0.15

For such key you need to parse path, which I left to you as I am not
good as JavaScript. Then you need simple reduce function for adding
this values.

Then you need to use group_level parameter. You can find some hints on
my blog: http://pawelstawicki.blogspot.com/2009/12/couchdb.html

If you have any problems don't hesitate to contact me.

Regards
-- 
Paweł Stawicki
http://pawelstawicki.blogspot.com
http://szczecin.jug.pl
http://www.java4people.com

Mime
View raw message