4
私は奇妙なMapReduceの問題があります。MapReduceの問題
地図機能:
> mp
function() {
emit(this.ContractID, {qty:this.Qty, qtybs:this.QtyBs});
}
7つの契約の機能
> red
function (key, values) {
var sum1 = 0, sum2 = 0;
values.forEach(function (doc) {sum1 += doc.qty;sum2 += doc.qtybs;});
return {a:sum1, b:sum2};
}
実行MRの削減:
> result = db.fact_payments.mapReduce(mp, red, {out:"myout2", query:{ContractID:{$lte:10000100042}}});
{
"result" : "myout2",
"timeMillis" : 670,
"counts" : {
"input" : 591,
"emit" : 591,
"output" : 7
},
"ok" : 1,
}
> db.myout2.find()
{ "_id" : NumberLong("10000000042"), "value" : { "a" : 8331.04, "b" : 253835.07999999996 } }
{ "_id" : NumberLong("10000000084"), "value" : { "a" : 4728.480000000001, "b" : 142879.88000000003 } }
{ "_id" : NumberLong("10000000129"), "value" : { "a" : 25421.859999999997, "b" : 756036.9499999998 } }
{ "_id" : NumberLong("10000000140"), "value" : { "a" : 477292.0000000002, "b" : 477292.0000000002 } }
{ "_id" : NumberLong("10000000148"), "value" : { "a" : 7912.0599999999995, "b" : 237926.87999999998 } }
{ "_id" : NumberLong("10000000165"), "value" : { "a" : 35391.31999999999, "b" : 1074180.95 } }
{ "_id" : NumberLong("10000000171"), "value" : { "a" : 62189.52, "b" : 62189.52 } }
>
それは大丈夫ですすべての、すべての契約は、結果を持っている:)
すべての契約でMRを実行するS:
異なる結果との契約のidの同じ> result = db.fact_payments.mapReduce(mp, red, {out:"myout2", query:{ContractID:{$lte:100100000042}}});
{
"result" : "myout2",
"timeMillis" : 26273,
"counts" : {
"input" : 295765,
"emit" : 295765,
"output" : 7793
},
"ok" : 1,
}
> db.myout2.find()
{ "_id" : NumberLong("10000000042"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10000000084"), "value" : { "a" : 4728.480000000001, "b" : 142879.88000000003 } }
{ "_id" : NumberLong("10000000129"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10000000140"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10000000148"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10000000165"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10000000171"), "value" : { "a" : 62189.52, "b" : 62189.52 } }
{ "_id" : NumberLong("10005000172"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10005000173"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10005000189"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10005000191"), "value" : { "a" : 8261.759999999998, "b" : 253916.7 } }
{ "_id" : NumberLong("10005000199"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10005000206"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10005000213"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10010000200"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10010000224"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10010000229"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10010000240"), "value" : { "a" : 32843.32, "b" : 32843.32 } }
{ "_id" : NumberLong("10010000243"), "value" : { "a" : NaN, "b" : NaN } }
{ "_id" : NumberLong("10010000244"), "value" : { "a" : NaN, "b" : NaN } }
has more
:私はすべての任意のアイデアを持っていない
{ "_id" : NumberLong("10000000042"), "value" : { "a" : 8331.04, "b" : 253835.07999999996 } }
と
{ "_id" : NumberLong("10000000042"), "value" : { "a" : NaN, "b" : NaN } }
。
うわー、ありがとう。私はこのルールを逃した。 – Igorekk