RethinkDB:减少迭代所有分组数据吗?
RethinkDB: does reduce iterate all grouped data?
我以为我用 rethinkdb 搞定了 :) 但现在我有点困惑 -
对于此查询,计算分组数据:
groupedRql.count()
我得到了预期的结果(数字):
[{"group": "a", "reduction": 41}, {"group": "b", "reduction": 39}...]
所有减少结果都是 ~40,这是预期的(并且是正确的),但是当我像这样使用 reduce 计算时:
groupedRql.map(function(row) {
return row.merge({
count: 0
})
}).reduce(function(left, right) {
return {count: left("count").add(1)}
})
我得到的结果要低得多 (~10),这毫无意义:
[{"group": "a", "reduction": 10}, {"group": "b", "reduction": 9}...]
当然,我需要使用 reduce 来进行进一步的操作。
我错过了什么吗?
我在服务器上使用 v2.0.3,直接在 dataexplorer 上测试查询。
问题出在这里
return {count: left("count").add(1)}
应该是
return {count: left("count").add(right("count"))}
减少运行多个分片之间的并行,多个CPU核心。当你做
return {count: left("count").add(1)}
您忽略了 right
中的某些计数。
本文档中注明:https://www.rethinkdb.com/docs/map-reduce/#how-gmr-queries-are-executed
it’s important to keep in mind that the reduce function is not called
on the elements of its input stream from left to right. It’s called on
either the elements of the stream in any order or on the output of
previous calls to the function.
我以为我用 rethinkdb 搞定了 :) 但现在我有点困惑 - 对于此查询,计算分组数据:
groupedRql.count()
我得到了预期的结果(数字):
[{"group": "a", "reduction": 41}, {"group": "b", "reduction": 39}...]
所有减少结果都是 ~40,这是预期的(并且是正确的),但是当我像这样使用 reduce 计算时:
groupedRql.map(function(row) {
return row.merge({
count: 0
})
}).reduce(function(left, right) {
return {count: left("count").add(1)}
})
我得到的结果要低得多 (~10),这毫无意义:
[{"group": "a", "reduction": 10}, {"group": "b", "reduction": 9}...]
当然,我需要使用 reduce 来进行进一步的操作。 我错过了什么吗?
我在服务器上使用 v2.0.3,直接在 dataexplorer 上测试查询。
问题出在这里
return {count: left("count").add(1)}
应该是
return {count: left("count").add(right("count"))}
减少运行多个分片之间的并行,多个CPU核心。当你做
return {count: left("count").add(1)}
您忽略了 right
中的某些计数。
本文档中注明:https://www.rethinkdb.com/docs/map-reduce/#how-gmr-queries-are-executed
it’s important to keep in mind that the reduce function is not called on the elements of its input stream from left to right. It’s called on either the elements of the stream in any order or on the output of previous calls to the function.