Well im trying translate this sql query to map reduce
select
o_orderpriority,
count(*) as order_count
from
orders
where
o_orderdate >= date '1993-07-01'
and o_orderdate < date '1993-07-01' + interval '3' month
and exists (
select
*
from
lineitem
where
l_orderkey = o_orderkey
and l_commitdate < l_receiptdate
)
group by
o_orderpriority
order by
o_orderpriority;
Ive tried the following map reduce function
db.runCommand({
mapreduce: "orders",
query: {
o_orderdate: {'$gte': new Date("July 01, 1993")},
o_orderdate: {'$lt': new Date("Oct 01, 1993")}
},
map: function Map() {
for(var i in this.o_lineitem) {
if( this.o_lineitem[i].l_commitdate < this.o_lineitem[i].l_receiptdate) {
var o_orderpriority = this.o_lineitem[i].o_orderpriority;
emit( o_orderpriority, {count: 1} );
}
}
},
reduce: function(key, values) {
var count= 0;
for (var i = 0; i < values.length; i++) {
count+= values[i];
}
return count;
},
out: 'query004'
});
when a i run i get the follow alert
Sat Aug 11 20:44:32 SyntaxError: missing ) after condition (shell):9
For me there's no ) missing, is it there?
I did the corrections pointed by @Stenie, but now a i have the follow problem
{
"assertion" : "value too large to reduce",
"assertionCode" : 13070,
"errmsg" : "db assertion failure",
"ok" : 0
}
emit(this.o_lineitem[i].o_orderpriority, count_order: 1);but should beemit(this.o_lineitem[i].o_orderpriority, count_order);.emit(this.o_lineitem[i].o_orderpriority, { count_order: 1 }). Note that your reduce is usingorder_countand doesn't appear to be writing any results into theretvalue.