incubator-couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harish Mallipeddi" <harish.mallipe...@gmail.com>
Subject Re: Changes in trunk
Date Thu, 22 May 2008 14:53:49 GMT
Hi,

What's the behavior of the reduce() in CouchDB? It seems to be different
from what Hadoop's map/reduce implementation offers.

After reading Damien Katz's blog post (
http://damienkatz.net/2008/02/incremental_map.html), I tried the following:

_design/categories (category is a string):

"views": {
    "counts": {
        "map": "function(doc) { emit(doc.category, 1); }",
        "reduce": "function(cat, counts) {
                    var sum = 0;
                    for(var i=0;i<counts.length;i++) {
                        sum += counts[i];
                    }
                    return sum;
                }"
    }
}

When I GET http://localhost:5984/blog/_view/categories/counts, somehow
CouchDB tries to cleverly "sum" up the counts of all categories and return
something like below:

{ "ok": true, "result": 6 }

Same thing happens when I do a range query -
http://localhost:5984/blog/_view/categories/counts?start_key=
"erlang"&end_key="ruby"

Shouldn't it return a list of <category, sum> pairs instead?

Actually I got a weirder response when I tried emitting strings instead of
ints.

Cheers,
Harish

On Thu, May 22, 2008 at 2:08 AM, Jan Lehnardt <jan@apache.org> wrote:

> Dear CouchDB aficionados,
> we made a couple of changes in trunk that are
> not backward compatible with earlier versions
> of CouchDB. Theses are necessary changes
> and we do them now in preparation for an 0.8
> release.
>
> If you have software that uses CouchDB, it is
> likely to require changing. Sorry about that :-)
>
> The changes in detail:
>
> Views now support optional reduce. For this
> to work, the structure of view documents
> had to change. An example is probably the
> best way to illustrate them:
>
> {
>  "_id":"_design/foo",
>  "language":"javascript",
>  "views": {
>    "bar": {
>      "map":"function... ",
>      "reduce":"function..."
>    }
>  }
> }
>
> Notable changes are the usage of a JSON object
> to define both the map and the reduce function instead
> of just a string for the map function. Again, the reduce
> member may be omitted.
>
> The "language" member is no longer a "proper"
> MIME-Type, instead, only the actual language's
> name is stated.
>
> Confusingly, we used a "map()" function to be used
> within the actual map function (or view function) to
> place a key and value in a view's result list. This
> function is now called "emit()" to avoid confusion.
>
> function(doc) {
>  emit(doc.foo, null);
> }
>
> Temporary views now need to get POSTed a
> proper JSON document with map and reduce
> members instead of just posting in the map function's
> source:
>
> {
>  "map":"function...",
>  "reduce":"function..."
> }
>
> Note that the language of the view functions is no
> longer determined by the Content-Type header of
> the HTTP request. Since the definition is a JSON object,
> the Content-Type is always application/json.
>
> {
>  "language":"javascript"
>  "map":"function...",
>  "reduce":"function..."
> }
>
>
> You specify the language of the temp view in an optional
> "language" member. If omitted, it's value defaults to
> "javascript".
>
>
>
>


-- 
Harish Mallipeddi
http://circos.com : http://poundbang.in

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message