gpt4 book ai didi

couchdb - 减少产出必须收缩得更快,这个错误是关于什么的?

转载 作者:行者123 更新时间:2023-12-02 15:12:11 24 4
gpt4 key购买 nike

用户可以在一个线程中发布多个评论,我尝试获取用户对其发表评论的线程(不同)列表,例如:-

// comment table (relation table)
id, thread_id, user_id

select comment.thread_id, count(*)
from user
inner join comment on user.id=comment.user_id
where user.id = ?
group by comment.thread_id;

这在 MySQL 中非常简单。
但要转换为 couchdb :-

// map
function(doc)
{
emit(doc.user_id, doc.thread_id);
}

// reduce
function (key, thread_id)
{
return thread_id;
}

如果我使用上面的 map 功能,我会遇到如下错误:-

"error": "reduce_overflow_error","reason": "Reduce output must shrink more rapidly: Current output: ...

I think I have applied the reduce function in wrong manner.

If using another way, like :-

// map
function (doc)
{
emit([doc.user_id, doc.thread_id], 1);
}

// reduce
function(keys, values)
{
return sum(values);
}

group=true 结果与 mysql group-by 的结果完全相同。
但是,我无法获取用户的所有线程列表(假设我在查询期间只有 user_id)

第三种方式,我可以放弃使用 MapReduce,直接应用:-

emit(doc.user_id, doc.thread_id);

并执行 PHP 数组,例如

foreach ( ... )
{
$threads[$thread_id] = TRUE;
}
array_keys($threads);

但是,这相当臃肿且效率较低。

第二种方法看起来更准确:-

key=[user_id, *] <-- it does not work, believe only work on exact match

key=[user_id, thread_id] <-- return one row

有没有办法在不知道 thread_id 的情况下获取所有结果?

(ps:我是 couchdb 的新手,我可能以不好的方式描述了该场景)

我通过@jasonsmith获得的一些引用资料:- http://guide.couchdb.org/draft/cookbook.html

As a rule of thumb, the reduce function should reduce to a single scalar value. That is, an integer; a string; or a small, fixed-size list or object that includes an aggregated value (or values) from the values argument. It should never just return values or similar. CouchDB will give you a warning if you try to use reduce “the wrong way”:

最佳答案

请密切关注本文档的内容:- http://wiki.apache.org/couchdb/View_Snippets#Generating_a_list_of_unique_values

// map
function(doc)
{
emit([doc.user_id, doc.thread_id], null);
}

// reduce
function (keys, values)
{
return null;
}

查询:-

?startkey=["$uid"]&endkey=["$uid",{}]&group=true

现在结果是准确的,
所以问题在于reduce函数以及查询的构造方式。

关于couchdb - 减少产出必须收缩得更快,这个错误是关于什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8324248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com