incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fabio Forno <fabio.fo...@gmail.com>
Subject Re: counting rows in range queries
Date Thu, 30 Jul 2009 07:56:43 GMT
On Thu, Jul 30, 2009 at 9:15 AM, Paul Davis<paul.joseph.davis@gmail.com> wrote:
> On Thu, Jul 30, 2009 at 2:53 AM, Fabio Forno<fabio.forno@gmail.com> wrote:
>> On Thu, Jul 30, 2009 at 3:22 AM, Paul Davis<paul.joseph.davis@gmail.com> wrote:
>>>>
>>>
>>> My bad, that should read 'emit([doc.bucket, doc.date], value)'
>>>
>>
>> Well but it doesn't work either, since when I retrieve the view I get
>> as many rows as the selected docs, with count 1. Perhaps my
>> description was confusing, since date is not something like YYMMDD,
>> but YYMMDDhhmmss. Therefore all the emitted keys are different and the
>> reduce function can't do any aggregation.
>>
>
> This doesn't matter at all.
>

Why? I've got these functions, which are pretty similar to your ones:

map:
function(doc) {
  if(doc.type == "item") {
    emit([doc.node, doc.data.updated], null);
  }
}

reduce:
function(key, values, rereduce) {
  if(rereduce) {
    return sum(values);
  } else {
    return values.length;
  }


The node is the bucket name, updated is when the item has been
inserted (converted to seconds from the epoc). Then I retrieve this
view (cut & paste from the browser), in which I want all the docs
newer then 1248650362

http://zafferano.ooros.priv:5984/test-rss/_design/items/_view/test_count?group=true&startkey=[%22https://identi.ca/api/statuses/public_timeline.rss%22,%201248670629]&endkey=[%22https://identi.ca/api/statuses/public_timeline.rss%22,%20%22%22]

What I get is:

{"rows":[
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670629],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670630],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670634],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670682],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670704],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670718],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670729],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670747],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670773],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670781],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670789],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670801],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670803],"value":2},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670805],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670806],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670813],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670835],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670839],"value":1},
{"key":["https://identi.ca/api/statuses/public_timeline.rss",1248670842],"value":1}
]}

I really can't understand what I'm doing wrong...

>
> Total rows always reflects the number of rows in the view. It can
> cause some confusion, but the other way around I don't know that it'd
> cause any less.
>
> Also, are you checking the value of the assumed single return row? If
> you're not getting a single returned row then something is wrong. If
> you are and it's wrong, then its wrong or I'm wrong. Either way, I'm
> confused...
>

Indeed... I'm not getting a single returned row and I can't figure out
how it can happen since date changes for each row
(It is clear to me how count all the items in a bucket, but not how to
do it in a range of dates specified in the query paramentes...)

bye

-- 
Fabio Forno, Ph.D.
Bluendo srl http://www.bluendo.com
jabber id: ff@jabber.bluendo.com

Mime
View raw message