One thing that took me a while to grasp is that you can't rely on the the keys (within a reduce range) being reduced in any particular order. I did the tests an on a large dataset it's off by ~5% because keys aren't always ordered in reduce. Many times the best answer is one of the built-in reduces like _count or _sum
Chris. On Wednesday, April 16, 2014 10:06:37 PM UTC-7, Johnny Caveman wrote: > > Ah, so the parameter of reduce( keys, values, re-reduce ) is based on each > of grouped result, I see. Thank you for answering the beginner level > question. > > I tried to log the activity of reduce block and I found it runs only once > for each document, no matter what the groupLevel is given. That's a bit > different from my assumption, say I got 3 records (color, type) and 2 of > them have the exact same key and the 3rd is totally different. My > assumption is when groupLevel is 1, couch separates them into two groups > and call the reduce function twice. But the logger says reduce is called 3 > times although the final result is correct. I'm curious what's behind the > scene makes the magic job ? > > > On Thursday, 17 April 2014 06:35:45 UTC+10, Jens Alfke wrote: >> >> >> On Apr 16, 2014, at 9:31 AM, Johnny Caveman <[email protected]> wrote: >> >> Let's say if after map process, the document's key is an date-type-color >> array, and value is some concrete value need to be aggregated, how to write >> a REDUCEBLOCK equivalent to *_count*, which allows you to drill down >> when aggregating associated with groupLevel. Just like >> this<http://blog.couchbase.com/understanding-grouplevel-view-queries-compound-keys> >> . >> >> >> Just write a trivial reduce block that counts rows. Setting the >> groupLevel will aggregate the keys together, and the reduce block will give >> you a count. >> So if you set the groupLevel to 1, you’ll get a row for each date whose >> value is the number of items with that date. >> >> —Jens >> > -- You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/2c101fbe-8a80-470a-8800-ec8272e61c6f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
