couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: on Reduce w/ Python view server
Date Tue, 20 Jan 2009 00:25:43 GMT
On Mon, Jan 19, 2009 at 7:15 PM, Jeff Hinrichs - DM&T
<jeffh@dundeemt.com> wrote:
> Using couchdb-python 0.5 and couchdb 0.9.0a735191-incubating
>
> I am working on a "rosetta stone" for javascript and python views. (nothing
> like rewriting in a different language to lean something<g>) I've worked
> though the simple map only views.  I then did a simple reduce(keys,vals)
> which worked out fine.  But I am stumped on rereduce when the function
> signature includes keys,vals,rereduce.  I've been trying to work through the
> js code from "Top N Tags" from the snippets page,
> http://wiki.apache.org/couchdb/View_Snippets
>
> In particular, I am confused as to what is passed to the rereduce function
> when rereduce=True.  The javascript is returning a complex structure instead
> of a simple scalar, I see that it has to do with getting state back from a
> previous reduce operation, but I'm confused. The unpacking of the previous
> results, I think has me befuddled ;(
>

The reduce function is always returning a structure of the form:

{
    "tag1": N1,
    "tag2": N2,
    ...
}

When you get to rereduce=true, then the values array is an array of
the structures that your code needs to combine.

And for berevity, the last bit of code outside the if statement is
just discarding all tags below the top N so that the growth of data
doesn't exceed the log(num_rows) rule.

HTH,
Paul Davis

>
> Any help is appreciated.
>
>
> Regards,
>
> Jeff
> p.s. Yes, I'd be happy to make a wiki page out of my work, but I'm not sure
> where it belongs, couchdb wiki or the couchdb-python wiki.
>

Mime
View raw message