I have read a text file and inserted data to Riak DB using python.
csv_data = csv.reader(file('abc.txt'))
txt file contains two field separated with @@
tempstring = str(row).split('@@')
and inserted in riak DB
new_user = user_buckets.new(FirstUser,data={
'user':FirstUser,
'friendlist':FriendList,
'is_active':True
})
new_user.store()
to fetch the data from Riak DB i use Map
user_buckets.map("""
function(v) {
var data = JSON.parse(v.values[0].data);
if(data.is_active == true) {
return [[v.key, data]];
}
return [];
}
""")
for result in user_buckets.run():
print "%s - %s" % (result[0], result[1])
and it gives in the format
Dinesh - {u'friendlist': [u'Bakshi', u' Kishna'], u'is_active': True, u'user': u'Dinesh'}
Here how can I remove u in the output format? Does converting to string while inserting to Riak cause to form u?
Edit 1
I fetched Riak DB using mapreduce
function(v) {
var data = JSON.parse(v.values[0].data);
var mapped = [];
var grouping = [];
if(data.is_active == true) {
userValue = data.user;
friendListValue = data.friendlist;
for (var i=0; i<friendListValue.length; i++){
friendValue = friendListValue[i];
mapped.push([userValue, friendValue, friendListValue]);
grouping.push([mapped[i]]);
}
}
}
Here grouping is multidimensional array which contains data like
Example
[u'Dinesh', u'Shiva', [u'Bakshi', u' Kishna', u' Hanks', u' Shiva', u' Bindu', u' Hari', u' Karma', u' Sita']]
[u'Shiva', u'Dinesh', [u'Hanks', u' Tom', u' Karma', u' Hari', u' Dinesh']]
and when i am comparing the values in array using
if(grouping[j][0]==grouping[k][1]&& grouping[j][1]==grouping[k][0])
In the above given like example case, it should return true but it gives error. So i think it is due to u. Now how can i compare the array and find out the match case? here i think i made a mistake in if condition.