Hello everybody,
I have just signed up on this list so please forgive me if this topic has been covered.

I am currently using the latest trunk version of CouchDB to experiment with it's features and I was experimenting with doing reports and using some views to run some data.
My map and reduce functions are:
Map:
function(doc) {
 if(doc.pc && doc.cc){
    emit([doc.cc,doc.pc,doc.task,doc.timestamp],doc.duration);
 }
}

Reduce:
function(keys, values) {
 return sum(values)
}

This produces a result like:

{"rows":[
{"key":["ACT","TXP","",1250825678],"value":5},
{"key":["ACT","TXP","",1250825960],"value":5},
{"key":["ACT","TXP","",1250827265],"value":5},
{"key":["HYD","SPR","blah",1250825378],"value":5},
{"key":["HYD","SPR","blah",1250825660],"value":5},
{"key":["HYD","SPR","blah",1250826965],"value":5},
{"key":["HYD","SPR","Phone",1250791287],"value":1},
{"key":["HYD","SPR","Phone",1250791355],"value":3}
]}

This is to be expected However I get some strange things happening if I filter this:
/taskreport?startkey=["HYD","","",1250825660]&endkey=["HYD","\u9999","\u9999",1250826965]&group=true
{"rows":[
{"key":["HYD","SPR","blah",1250825378],"value":5},
{"key":["HYD","SPR","blah",1250825660],"value":5},
{"key":["HYD","SPR","blah",1250826965],"value":5},
{"key":["HYD","SPR","Phone",1250791287],"value":1},
{"key":["HYD","SPR","Phone",1250791355],"value":3}
]}

I would have thought that since my startkey value is greater than the first row this should only return the last 4 rows
and in fact if I send specific data for the 2nd and 3rd keys this works:
/taskreport?startkey=["HYD","SPR","blah",1250825660]&endkey=["HYD","SPR","blah",1250826965]&group=true
{"rows":[
{"key":["HYD","SPR","blah",1250825660],"value":5},
{"key":["HYD","SPR","blah",1250826965],"value":5}
]}

I then try and group limit this result so I can group by ["HYD","SPR","blah"], hence the reason for putting the timestamp field at the end of the keys.
/taskreport?startkey=["HYD","SPR","blah",1250825660]&endkey=["HYD","SPR","blah",1250826965]&group=true&group_level=3
{"rows":[
{"key":["HYD","SPR","blah"],"value":10}
]}
Which also works as expected.

So my question is with using start/end keys should it filter on each individual part of the key? Should not startkey=["HYD","","",1250825660]&endkey=["HYD","\u9999","\u9999",1250826965]&group=true return
{"rows":[
{"key":["HYD","SPR","blah",1250825660],"value":5},
{"key":["HYD","SPR","blah",1250826965],"value":5}
]}
as well? How could I get this working? BTW If I try a group_level on this
/taskreport?startkey=["HYD",null,null,1250825660]&endkey=["HYD",{},{},1250826965]&group=true&group_level=3
I get :
{"rows":[
{"key":["HYD","SPR","blah"],"value":15},
{"key":["HYD","SPR","Phone"],"value":4}
]}


Thanks, in advance, for any help :)

Regards
Andrew Mee










Reply via email to