好吧,我正在尝试将此 sql 查询翻译为 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;
我尝试了以下地图减少功能
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'
});
当 ai 运行时,我会收到以下警报
Sat Aug 11 20:44:32 SyntaxError: missing ) after condition (shell):9
对我来说,没有 ) 丢失,是吗?
我做了@Stenie指出的更正,但现在ai有以下问题
{
"assertion" : "value too large to reduce",
"assertionCode" : 13070,
"errmsg" : "db assertion failure",
"ok" : 0
}