CouchDB的group = true是否可以防止还原? [英] Does CouchDB's group=true prevent rereduce?

查看:65
本文介绍了CouchDB的group = true是否可以防止还原?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CouchDB的map函数发出键/值对:

CouchDB's map functions emit key/value pairs:

function(doc) {
  emit(doc.date, 1);
}

可能会有许多键/值对具有相同的键。在查询视图时设置 group = true 将具有相同键的键/值对分组到相同的reduce中:

Potentially, there could be many key/value pairs with the same key. Setting group=true while querying a view groups key/value pairs with the same key into the same reduce:

function(keys, values, rereduce) {
  return sum(values);
}

这是否意味着 group = true (或任何 group_level > 0),每个键会只减少一个键吗?

Does this mean that with group=true (or for any group_level > 0), there will be exactly one reduce per key?

还是分组仅保证所有的reduces都具有同质键,并且仍然可能存在一个或多个rereduce?

Or does the grouping only guarantee that all reduces will have homogeneous keys, and that there could still be one or more rereduces?

我是使用非交换性但不会每个键包含大量记录的reduce函数。我希望我能够设置 group = true ,然后在单个reduce中控制操作顺序。如果有减少的机会,那么该计划就没有意义。

I am working with a reduce function that is not commutative, but which will not have a large number of records per key. I was hoping that I would be able to set group=true and then control the order of operation within a single reduce. If there will be rereduces, then that plan does not make sense.

推荐答案

group = true 大致表示嘿,沙发!以所有键都不同的方式对地图进行分组,但是不要错过任何情况! 实际上等于 group_level = 999 (请参见文档)。

group=true roughly means "Hey, Couch! Group this map in the way there all keys will be distinct, but don't miss any case of them!" and actually equals to group_level=999 (see docs).

虽然您可能无法猜出正确的 group_level 并剥离一些键项(如果键是数组,则很有意义) , group 会为您解决此问题,并且不会应用rereduce。

While you may not guess with proper group_level and strip some key items (if key is an array it makes sense), group takes care of this for you and rereduce wouldn't be applied.

此外,您的reduce函数可以被内置的 _sum 替换-它在Erlang中实现,并且速度更快。

Also, your reduce function could be replaced with the built-in _sum - it's implemented in Erlang and is much faster.

这篇关于CouchDB的group = true是否可以防止还原?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆