You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Johannes Schneider <ma...@cedarsoft.com> on 2010/09/09 15:08:41 UTC
Testing map/reduce functions
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi guys,
I would like to test my map and reduce functions without CouchDB. I'd
like to write some unit tests that verify that those functions work as
expected...
Does anybody out there have any hints how this can be done? If it is
Java based and portable this would be great...
Thanks,
Johannes
- --
Johannes Schneider - blog.cedarsoft.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQEcBAEBAgAGBQJMiNxWAAoJEAytD9R7Qv6dtPQH/A6OetCJm7KOjHIFVgBBWPcD
aFR8xHqKIjALjZg5jPwm5ALw+2tDaPhKIjU0JAv3tfHiuqHdpUUe9z+y0Oz3j5ey
Mn6B7qr2KhIN3VGJGC5GOGkQoHmeMaJ2rus2ETr8TmwxXk+bXV0I0nn9K6D+CKP9
c6G5YXGnA5mc6vScRERGyburb6ltp0C6glK2me/F/BmCDs8oEoBpiYh6KGP/lxK2
P+B1TqvAPHCYL2vqulUN4/gD3ceme6vlqqaL74JpD+3z4yuj82ljg94Gk6AfzVVU
cEyexX2/oet7f9OLiuZiOWyYGSq+a/R87uKA42Hr2w9HR0fEfOo4Qxjr9gQY+iw=
=pJe2
-----END PGP SIGNATURE-----
Re: Testing map/reduce functions
Posted by Vivek Pathak <vp...@orgmeta.com>.
Unit testing and debugging view functions without any code changes can
be done, as discussed here:
https://github.com/vivekpathak/casters
Since the "todo list" talking about test cases - while trivial - is over
three years old, it probably is okay to share here.
Thanks!
Re: Testing map/reduce functions
Posted by J Chris Anderson <jc...@apache.org>.
On Sep 13, 2010, at 9:11 AM, Thomas Rampelberg wrote:
> It would be epically awsome to have unit test functionality for
> map/reduce baked into couchapp .....
>
On my infinite todo list is the idea to implement CouchApp in Node.js, which would make adding extensions like this "trivial."
I doubt that will ever get to the top of my list, so if someone else takes it on that'd be rad. Work should probably be coordinated on the CouchApp list:
http://groups.google.com/group/couchapp/
Chris
> On Mon, Sep 13, 2010 at 8:49 AM, Mark J. Reed <ma...@gmail.com> wrote:
>> On Mon, Sep 13, 2010 at 11:08 AM, Paweł Stawicki
>> <pa...@gmail.com> wrote:
>>> You can take a look on my blog post:
>>> http://pawelstawicki.blogspot.com/2009/12/couchdb.html
>>> At the end are reduce parameters explained.
>>
>> Nitpick: this reduce call given in your post is invalid:
>>
>>> function(["developer", "manager", "administrator"], [17, 4, 2], true);
>>
>> Because when rereduce is true, the first parameter (keys) is presumably null.
>>
>> Basically, a map function emits a (key, value) pair; the plumbing
>> automatically adds the document id that was being processed when the
>> pair was emitted, so what you get out of the map phase is essentially
>> a bunch of triples: (key1, value1, document1), (key2, value2,
>> document2), etc.
>>
>> The reduce function, pre-rereduce, gets some subset of those triples,
>> slightly re-organized. A single call to reduce might look like this:
>>
>> reduce([[key1, document1], [key2, document2], [value1, value2], false)
>>
>> Unlike classical map/reduce, the reduce function is not guaranteed to
>> get all of the values associated with a given key. Nonetheless, it is
>> expected to return a single result value (which may be a complex value
>> like an array or object).
>>
>> The results of the reduce function may be passed back into another
>> reduce pass. In this case, there are no keys, values, or documents,
>> just a single array of results from a previous call to the same reduce
>> function.
>>
>> reduce(null, [reduced1, reduced2, reduced3], true)
>>
>> -
>> Mark J. Reed <ma...@gmail.com>
>>
Re: Testing map/reduce functions
Posted by Thomas Rampelberg <py...@gmail.com>.
It would be epically awsome to have unit test functionality for
map/reduce baked into couchapp .....
On Mon, Sep 13, 2010 at 8:49 AM, Mark J. Reed <ma...@gmail.com> wrote:
> On Mon, Sep 13, 2010 at 11:08 AM, Paweł Stawicki
> <pa...@gmail.com> wrote:
>> You can take a look on my blog post:
>> http://pawelstawicki.blogspot.com/2009/12/couchdb.html
>> At the end are reduce parameters explained.
>
> Nitpick: this reduce call given in your post is invalid:
>
>> function(["developer", "manager", "administrator"], [17, 4, 2], true);
>
> Because when rereduce is true, the first parameter (keys) is presumably null.
>
> Basically, a map function emits a (key, value) pair; the plumbing
> automatically adds the document id that was being processed when the
> pair was emitted, so what you get out of the map phase is essentially
> a bunch of triples: (key1, value1, document1), (key2, value2,
> document2), etc.
>
> The reduce function, pre-rereduce, gets some subset of those triples,
> slightly re-organized. A single call to reduce might look like this:
>
> reduce([[key1, document1], [key2, document2], [value1, value2], false)
>
> Unlike classical map/reduce, the reduce function is not guaranteed to
> get all of the values associated with a given key. Nonetheless, it is
> expected to return a single result value (which may be a complex value
> like an array or object).
>
> The results of the reduce function may be passed back into another
> reduce pass. In this case, there are no keys, values, or documents,
> just a single array of results from a previous call to the same reduce
> function.
>
> reduce(null, [reduced1, reduced2, reduced3], true)
>
> -
> Mark J. Reed <ma...@gmail.com>
>
Re: Testing map/reduce functions
Posted by "Mark J. Reed" <ma...@gmail.com>.
On Mon, Sep 13, 2010 at 11:08 AM, Paweł Stawicki
<pa...@gmail.com> wrote:
> You can take a look on my blog post:
> http://pawelstawicki.blogspot.com/2009/12/couchdb.html
> At the end are reduce parameters explained.
Nitpick: this reduce call given in your post is invalid:
> function(["developer", "manager", "administrator"], [17, 4, 2], true);
Because when rereduce is true, the first parameter (keys) is presumably null.
Basically, a map function emits a (key, value) pair; the plumbing
automatically adds the document id that was being processed when the
pair was emitted, so what you get out of the map phase is essentially
a bunch of triples: (key1, value1, document1), (key2, value2,
document2), etc.
The reduce function, pre-rereduce, gets some subset of those triples,
slightly re-organized. A single call to reduce might look like this:
reduce([[key1, document1], [key2, document2], [value1, value2], false)
Unlike classical map/reduce, the reduce function is not guaranteed to
get all of the values associated with a given key. Nonetheless, it is
expected to return a single result value (which may be a complex value
like an array or object).
The results of the reduce function may be passed back into another
reduce pass. In this case, there are no keys, values, or documents,
just a single array of results from a previous call to the same reduce
function.
reduce(null, [reduced1, reduced2, reduced3], true)
-
Mark J. Reed <ma...@gmail.com>
Re: Testing map/reduce functions
Posted by Paweł Stawicki <pa...@gmail.com>.
You can take a look on my blog post:
http://pawelstawicki.blogspot.com/2009/12/couchdb.html
At the end are reduce parameters explained.
Best regards
--
Paweł Stawicki
http://pawelstawicki.blogspot.com
http://szczecin.jug.pl
On Mon, Sep 13, 2010 at 17:02, Johannes Schneider
<ma...@cedarsoft.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I have done something similar. But I don't understand the parameters for
> the reduce functions (yet). Could you paste me your mock
> implementations/calls for the reduce functions?
>
>
> Thanks,
>
> Johannes
>
> On 09/10/2010 12:58 PM, Julian Doherty wrote:
>> I've used Rhino (Java based Javascript interpreter) to test map/reduce
>> functions before. You need to expose an "emit" function and probably make
>> assertions on what gets passed to it.
>>
>> Apart from that the map/reduce functions as called by Couch are pretty
>> idempotent, so are easy to test in isolation.
>>
>> On 9 September 2010 23:08, Johannes Schneider <ma...@cedarsoft.com>wrote:
>>
>> Hi guys,
>>
>> I would like to test my map and reduce functions without CouchDB. I'd
>> like to write some unit tests that verify that those functions work as
>> expected...
>>
>> Does anybody out there have any hints how this can be done? If it is
>> Java based and portable this would be great...
>>
>>
>> Thanks,
>>
>> Johannes
>>>
>
> - --
> Johannes Schneider - blog.cedarsoft.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iQEcBAEBAgAGBQJMjj0fAAoJEAytD9R7Qv6dB0AIAM4uheyZxNWucvPQ5G61T/k+
> 4OVpBg4iDtIlBkLoZN36tYvETtHyuQErEldtFJxintxDR9lUlt5H0Qo+s015/DXw
> drtcRbt3CHMDVIsYgh35YdEPx+A4Yyiz52QtScSbQwKYeSfRWgPGHm/H606klRrL
> R83cPn6Rxioy2MtX0qlPyPNVqTcqa494EnZRjbKuYVSZh8D2p1pOJFUyN5+d1rLI
> 4QDR4B2lyb2XcDfa88GLMj1KKbSYT0WiCpobkUpJWdUnxhZYAQdIQBggsssYwBGc
> i8i5QyCwBPNQLnvN8GJ5vqP/ZFKOXNrdqrHjYZRyRir6z2H92IPJlzTOvfoUZOc=
> =1IPr
> -----END PGP SIGNATURE-----
>
Re: Testing map/reduce functions
Posted by Johannes Schneider <ma...@cedarsoft.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have done something similar. But I don't understand the parameters for
the reduce functions (yet). Could you paste me your mock
implementations/calls for the reduce functions?
Thanks,
Johannes
On 09/10/2010 12:58 PM, Julian Doherty wrote:
> I've used Rhino (Java based Javascript interpreter) to test map/reduce
> functions before. You need to expose an "emit" function and probably make
> assertions on what gets passed to it.
>
> Apart from that the map/reduce functions as called by Couch are pretty
> idempotent, so are easy to test in isolation.
>
> On 9 September 2010 23:08, Johannes Schneider <ma...@cedarsoft.com>wrote:
>
> Hi guys,
>
> I would like to test my map and reduce functions without CouchDB. I'd
> like to write some unit tests that verify that those functions work as
> expected...
>
> Does anybody out there have any hints how this can be done? If it is
> Java based and portable this would be great...
>
>
> Thanks,
>
> Johannes
>>
- --
Johannes Schneider - blog.cedarsoft.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQEcBAEBAgAGBQJMjj0fAAoJEAytD9R7Qv6dB0AIAM4uheyZxNWucvPQ5G61T/k+
4OVpBg4iDtIlBkLoZN36tYvETtHyuQErEldtFJxintxDR9lUlt5H0Qo+s015/DXw
drtcRbt3CHMDVIsYgh35YdEPx+A4Yyiz52QtScSbQwKYeSfRWgPGHm/H606klRrL
R83cPn6Rxioy2MtX0qlPyPNVqTcqa494EnZRjbKuYVSZh8D2p1pOJFUyN5+d1rLI
4QDR4B2lyb2XcDfa88GLMj1KKbSYT0WiCpobkUpJWdUnxhZYAQdIQBggsssYwBGc
i8i5QyCwBPNQLnvN8GJ5vqP/ZFKOXNrdqrHjYZRyRir6z2H92IPJlzTOvfoUZOc=
=1IPr
-----END PGP SIGNATURE-----
Re: Testing map/reduce functions
Posted by Julian Doherty <ju...@gmail.com>.
I've used Rhino (Java based Javascript interpreter) to test map/reduce
functions before. You need to expose an "emit" function and probably make
assertions on what gets passed to it.
Apart from that the map/reduce functions as called by Couch are pretty
idempotent, so are easy to test in isolation.
On 9 September 2010 23:08, Johannes Schneider <ma...@cedarsoft.com>wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi guys,
>
> I would like to test my map and reduce functions without CouchDB. I'd
> like to write some unit tests that verify that those functions work as
> expected...
>
> Does anybody out there have any hints how this can be done? If it is
> Java based and portable this would be great...
>
>
> Thanks,
>
> Johannes
> - --
> Johannes Schneider - blog.cedarsoft.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iQEcBAEBAgAGBQJMiNxWAAoJEAytD9R7Qv6dtPQH/A6OetCJm7KOjHIFVgBBWPcD
> aFR8xHqKIjALjZg5jPwm5ALw+2tDaPhKIjU0JAv3tfHiuqHdpUUe9z+y0Oz3j5ey
> Mn6B7qr2KhIN3VGJGC5GOGkQoHmeMaJ2rus2ETr8TmwxXk+bXV0I0nn9K6D+CKP9
> c6G5YXGnA5mc6vScRERGyburb6ltp0C6glK2me/F/BmCDs8oEoBpiYh6KGP/lxK2
> P+B1TqvAPHCYL2vqulUN4/gD3ceme6vlqqaL74JpD+3z4yuj82ljg94Gk6AfzVVU
> cEyexX2/oet7f9OLiuZiOWyYGSq+a/R87uKA42Hr2w9HR0fEfOo4Qxjr9gQY+iw=
> =pJe2
> -----END PGP SIGNATURE-----
>