3

In Couchbase or CouchDB, is it possible to group without an explicit reduce function? In my client code, I want the data to be given to me just as a reduce would receive it (assuming all mappers were used as input, even during a rereduce). Using group=true without a defined reduce function gives me the error:

$ curl http://127.0.0.1:8092/default/_design/testing1/_view/all?group=true
{"error":"query_parse_error",
 "reason":"Invalid URL parameter 'group' or 'group_level' for non-reduce view."}

I can add the identity reduce function:

reduce(keys,data) {return data;}

but Couchbase complains that I'm not actually reducing anything:

{"rows":[], "errors":[
    {"from":"local","reason":"{<<"reduce_overflow_error">>,
        <<"Reduce output must shrink more rapidly: Current output: '...'
    }]}

I'd sure like to get the complete reduction in my client.

Jake Biesinger
  • 5,538
  • 2
  • 23
  • 25
  • Wouldn't that just return the same data as the view with no reduce function? Or are you trying to combine all the data for the same key into a single value? – Dusty Campbell Aug 08 '12 at 05:50
  • Yes, I'd like the view without a reduce, but grouped together by key. The map function yields {attribute : key} pairs, which I'd like to be grouped together on the attribute: {attr1 : [key1, key2, key3], attr2 : [key4, key5]} – Jake Biesinger Aug 10 '12 at 20:43

2 Answers2

1

This not a technological limitation, it's a logical limitation. You cannot logically group results without some reduction of those results. This is analogous to the GROUP BY in SQL, you can't use that unless you also have some sort of aggregate function in your SQL query.

smathy
  • 26,283
  • 5
  • 48
  • 68
  • But I can do an "identity reduce" as I mentioned, whose analogue doesn't exist in SQL. While I understand Couchbase is trying to keep me in the realm of high performance queries, the limitation seems arbitrary. – Jake Biesinger Jul 20 '12 at 20:48
0

The use of the "identity reduce" is a common pitfall in Couch-style map reduce. The Couch reduce system is designed for reduce functions that look more like:

function(keys, values) {
   return values.length;
}

The identity reduce will end up storing multiple copies of the map rows, in a non-indexed data structure.

It sounds like what you want is the unique set of keys, regardless of the reduction value. In that case, I would use the _count reduce function, since it is efficient and can run on any underlying data.

J Chris A
  • 2,158
  • 15
  • 14