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] <-- WTF... works for [v[0]], [v[1]], [v[2]] but fails from
[v[3]]...
REDUCE (try4:!!!!!): {"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 Reduce phase returns the data inside an array... but with a
wrong patter [[1,1,1,[1,1]]]!!!:
[
["{\"name\":\"lee\",\"dob\":1984,\"country\":\"Japan\"}",
"{\"name\":\"fernandez\",\"dob\":1983,\"country\":\"US\"}",
"{\"name\":\"rohman\",\"dob\":1982,\"country\":\"Taiwan\"}",
["{\"name\":\"antonio\",\"dob\":1981,\"country\":\"Spain\"}",
<---- See the weird extra array?
"{\"name\":\"bitch\",\"dob\":1985,\"country\":\"China\"}"]
]
]
that is transformed to this:
Array (
[0] => {"name":"lee","dob":1984,"country":"Japan"}
[1] => {"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
Antonio Rohman Fernandez
CEO, Founder & Lead Engineer
[email protected] Projects
MaruBatsu.es
PupCloud.com
Wedding Album
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com