annoying javascript problem in Reduce phases

Antonio Rohman Fernandez rohman at mahalostudio.com
Thu Mar 10 05:32:23 EST 2011



Dear All,
I'm having a pretty annoying Javascript problem and would
like to know if is a bug (most likely) or if somebody has a solution.


This is the sample data i'm playing with:
bucket ->
'testbucket'
key00001:{"name":"antonio","dob":1981,"country":"Spain"}
key00002:{"name":"rohman","dob":1982,"country":"Taiwan"}
key00003:{"name":"fernandez","dob":1983,"country":"US"}
key00004:{"name":"lee","dob":1984,"country":"Japan"}
key00005:{"name":"bruce","dob":1985,"country":"China"}


MAP ONLY:
{"inputs":"testbucket","query":[{"map":{"language":"javascript","source":"function(v,k,a)
{ return [v.values[0].data]; }"}}]}

The Mapping phase ( nothing
special, just gives back the values of all keys in the bucket ) gives
the correct data, an array of all my key's
values:
["{"name":"rohman","dob":1982,"country":"Taiwan"}",
"{"name":"bruce","dob":1985,"country":"China"}",
"{"name":"fernandez","dob":1983,"country":"US"}",
"{"name":"antonio","dob":1981,"country":"Spain"}",
"{"name":"lee","dob":1984,"country":"Japan"}"]


REDUCE (try1:OK):
{"inputs":"testbucket","query":[{"map":{"language":"javascript","source":"function(v,k,a)
{ return [v.values[0].data]; }"}},{"reduce":
{"language":"javascript","source":"function(v,a) { return v; }"}}]}


This kinda useless Reduce phase returns the data as it is, even the
order is reversed... seems
ok:
["{"name":"lee","dob":1984,"country":"Japan"}",
"{"name":"fernandez","dob":1983,"country":"US"}",
"{"name":"rohman","dob":1982,"country":"Taiwan"}",
"{"name":"antonio","dob":1981,"country":"Spain"}",
"{"name":"bruce","dob":1985,"country":"China"}"]

REDUCE
(try2:OK):
{"inputs":"testbucket","query":[{"map":{"language":"javascript","source":"function(v,k,a)
{ return [v.values[0].data]; }"}},{"reduce":
{"language":"javascript","source":"function(v,a) { return [v[1]]; }"}}]}


This Reduce phase just return the 2nd item array[1] of the result...
seems ok too!:
["{"name":"fernandez","dob":1983,"country":"US"}"]


REDUCE (try3:!!!!!):
{"inputs":"testbucket","query":[{"map":{"language":"javascript","source":"function(v,k,a)
{ return [v.values[0].data]; }"}},{"reduce":
{"language":"javascript","source":"function(v,a) { return [v[3]]; }"}}]}


This Reduce phase SHOULD return the 4th item of the array... but
returns NULL!!!!:
[null] 
{"name":"fernandez","dob":1983,"country":"US"}
 [2] =>
{"name":"rohman","dob":1982,"country":"Taiwan"}
 [3] => Array (
 [0] =>
{"name":"antonio","dob":1981,"country":"Spain"}
 [1] =>
{"name":"bruce","dob":1985,"country":"China"}
 )
)

I don't know what is
going on with the javascript Reduce phase... but is killing me...
return
v --> OK
return [v[0]] --> OK
return [v[1]] --> OK
return [v[2]] -->
OK
return [v[3]] --> ERROR ( and so on )

any ideas? thanks
Rohman

		
[1]

ANTONIO ROHMAN FERNANDEZ
CEO, Founder & Lead
Engineer
rohman at mahalostudio.com [2]		 
PROJECTS
MaruBatsu.es
[3]
PupCloud.com [4]
Wedding Album [5]

 

Links:
------
[1]
http://mahalostudio.com
[2] mailto:rohman at mahalostudio.com
[3]
http://marubatsu.es
[4] http://pupcloud.com
[5]
http://wedding.mahalostudio.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20110310/008ce311/attachment.html>


More information about the riak-users mailing list