incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Søren Hilmer ...@widetrail.dk>
Subject Re: Question on view design for both Hierarchy and Date.
Date Sun, 26 Sep 2010 11:02:06 GMT
Hi

A few questions to your comments

On Thu, Sep 23, 2010 at 10:06 PM, Wout Mertens <wout.mertens@gmail.com>wrote:

> 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
>

Yes, but will that allow me to do the sum on a monthly basis, like with this
query for september:
 startkey=["A","B","c6",2010,9,1]&endkey=["A","B","c6",2010,9,31,{}]


> - 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.
>

Hmm, if I do that how do I query the sum under for instance the root for a
period?
Let us say I have two paths ["A","B1","C1"] and ["A", "B2", "D1"]

If I do the query
startkey=["A","B1","C1",2010,9,20,15,0]&endkey=["A","B1","C1",2010,9,31,15,0{}]

Then I can group up the path using group_level=1 to get the sum under A for
the period given, but as I understand it only for the query issued, I will
not get the contribution from the B2 branch.

For this to be possible I believe I would need some kind of wildcard, so I
could specify something like:
startkey=["A","*","*",2010,9,20,15,0]&endkey=["A","*","*",2010,9,31,15,0{}]
To get all the branches under A but between the period given.

I do not believe that is possible, but please enlighten me, if I have missed
something.

Søren


>
> 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
> >
>



-- 

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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message