incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wout Mertens <wout.mert...@gmail.com>
Subject Re: Question on view design for both Hierarchy and Date.
Date Thu, 23 Sep 2010 20:06:18 GMT
2 comments:
- your time is a fixed-length string (until the year 10000 ;)) so you
could just leave it as-is instead of splitting it
- using group=true you can get the sum for each sub level in your key
array so you don't have to emit the full path. Just emit the path and
then the time.

I think.

Wout.

On Tuesday, September 21, 2010, Søren Hilmer <sh@widetrail.dk> wrote:
> Hi all
>
> I have documents which has a place in both a hierarchy and on a time line.
>
> So I wish to be able to query a view to get all documents (actually their
> value), under a node in the hierarchy and between two dates.
>
> A document could look like this:
> {
>    "path": [ "A", "B", "c6", "b9"],
>    "time": "2010-09-20T23:00:00.000Z",
>    "value": 117
> }
>
> I have come up with this map function, which emits every sub-path from the
> root together with the date for each document:
> function(doc) {
>     if (doc.value) {
>        var d = new Date(Date.parse(doc.time));
>        var r = [];
>        var p = [];
>        r.push(d.getFullYear());
>        r.push(d.getMonth()+1);
>        r.push(d.getDate());
>        r.push(d.getHours());
>        r.push(d.getMinutes());
>        r.push(d.getSeconds());
>
>        for (var i in doc.path) {
>            p.push(doc.path[i]);
>            emit(p.concat(r), doc.value);
>        };
>      }
> }
>
> //reduce just sums the values
>
> This allows me to do the wanted query
> like, startkey=["A","B","c6",2010,9,20,12,0,0]&endkey=["A","B","c6",2010,9,20,22,0,0,{}]
>
> Is there a better (for some value of better like: faster and/or uses less
> space) approach to this problem?
>
> The documents are actually only on the leaves in the hierarchy, but I need
> to sum their values up the tree, can this extra information somehow be used
> to improve the view?
>
> I can get up to 500.000 of these documents pr. hour. would that be a problem
> as I do several emits pr document?
>
> Any tips are welcome.
>
> Best
>    Søren
>
> --
>
> Søren Hilmer, M.Sc., M.Crypt.
>
> wideTrail                   Phone:  +45 25481225
>
> Pilevænget 41           Email:  sh at widetrail.dk <sh@widetrail.dk>
>
> DK-8961  Allingåbro   Web:    www.widetrail.dk
>

Mime
View raw message