summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2008-06-05 23:49:48 +0000
committerDamien F. Katz <damien@apache.org>2008-06-05 23:49:48 +0000
commit712830243c89a0863831ead8e983f089fd37fd42 (patch)
treeeb3f6f7cb8f08684f63d71869817cd898412ffd0 /src
parent43776b676961ec093556fa5693298463ecee2ff5 (diff)
Added reduce/combine example. Fixed broken node chunking with very large keys/reduction values
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@663786 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_btree.erl5
-rw-r--r--src/couchdb/couch_httpd.erl7
2 files changed, 8 insertions, 4 deletions
diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl
index f5111c28..f01234c1 100644
--- a/src/couchdb/couch_btree.erl
+++ b/src/couchdb/couch_btree.erl
@@ -255,7 +255,7 @@ chunkify(_Bt, [], _ChunkThreshold, OutList, _OutListSize, OutputChunks) ->
lists:reverse([lists:reverse(OutList) | OutputChunks]);
chunkify(Bt, [InElement | RestInList], ChunkThreshold, OutList, OutListSize, OutputChunks) ->
case size(term_to_binary(InElement)) of
- Size when (Size + OutListSize) > ChunkThreshold ->
+ Size when (Size + OutListSize) > ChunkThreshold andalso OutList /= [] ->
chunkify(Bt, RestInList, ChunkThreshold, [], 0, [lists:reverse([InElement | OutList]) | OutputChunks]);
Size ->
chunkify(Bt, RestInList, ChunkThreshold, [InElement | OutList], OutListSize + Size, OutputChunks)
@@ -398,6 +398,9 @@ modify_kvnode(Bt, [{Key, Value} | RestKVs], [{ActionType, ActionKey, ActionValue
end.
+reduce_stream_node(_Bt, _Dir, nil, _KeyStart, _KeyEnd, GroupedKey, GroupedKVsAcc,
+ GroupedRedsAcc, _KeyGroupFun, _Fun, Acc) ->
+ {ok, Acc, GroupedRedsAcc, GroupedKVsAcc, GroupedKey};
reduce_stream_node(Bt, Dir, {P, _R}, KeyStart, KeyEnd, GroupedKey, GroupedKVsAcc,
GroupedRedsAcc, KeyGroupFun, Fun, Acc) ->
case get_node(Bt, P) of
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index b9244b1b..da3d7555 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -469,7 +469,9 @@ output_reduce_view(Req, View) ->
Resp:write_chunk(AccSeparator ++ Json),
{ok, {",",0,AccCount-1}};
(Key, Red, {AccSeparator,0,AccCount})
- when is_tuple(Key) and is_integer(GroupLevel) ->
+ when is_integer(GroupLevel)
+ andalso is_tuple(Key)
+ andalso element(1, Key) /= obj ->
Json = lists:flatten(cjson:encode(
{obj, [{key, list_to_tuple(lists:sublist(tuple_to_list(Key), GroupLevel))},
{value, Red}]})),
@@ -557,8 +559,7 @@ handle_doc_request(Req, 'GET', _DbName, Db, DocId) ->
Json = lists:flatten(cjson:encode({obj, [{ok, JsonDoc}]})),
Resp:write_chunk(AccSeparator ++ Json);
{{not_found, missing}, RevId} ->
- Json = {obj, [{"missing", RevId}]},
- Json = lists:flatten(cjson:encode(Json)),
+ Json = lists:flatten(cjson:encode({obj, [{"missing", RevId}]})),
Resp:write_chunk(AccSeparator ++ Json)
end,
"," % AccSeparator now has a comma