couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [2/4] fabric commit: updated refs/heads/master to 1be5506
Date Sat, 26 Mar 2016 13:16:45 GMT
Support raw collation in reduce results

Also simplify find_next_key/3 and avoid generating a new fun for every
streamed key.

COUCHDB-2900


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/96fe423a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/96fe423a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/96fe423a

Branch: refs/heads/master
Commit: 96fe423aa1b92e91d35c4375c9d933eadea3305a
Parents: eeaa400
Author: Benjamin Anderson <b@banjiewen.net>
Authored: Tue Mar 15 22:17:41 2016 -0700
Committer: Benjamin Anderson <b@banjiewen.net>
Committed: Wed Mar 23 23:12:54 2016 -0700

----------------------------------------------------------------------
 src/fabric_view.erl        | 30 ++++++++++++++++--------------
 src/fabric_view_reduce.erl | 11 ++++++-----
 2 files changed, 22 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/96fe423a/src/fabric_view.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view.erl b/src/fabric_view.erl
index 32369cd..50896cf 100644
--- a/src/fabric_view.erl
+++ b/src/fabric_view.erl
@@ -204,13 +204,14 @@ get_next_row(#collector{rows = []}) ->
     throw(complete);
 get_next_row(#collector{reducer = RedSrc} = St) when RedSrc =/= undefined ->
     #collector{
-        query_args = #mrargs{direction=Dir},
+        query_args = #mrargs{direction = Dir},
         keys = Keys,
         rows = RowDict,
         lang = Lang,
-        counters = Counters0
+        counters = Counters0,
+        collation = Collation
     } = St,
-    {Key, RestKeys} = find_next_key(Keys, Dir, RowDict),
+    {Key, RestKeys} = find_next_key(Keys, Dir, Collation, RowDict),
     case dict:find(Key, RowDict) of
     {ok, Records} ->
         NewRowDict = dict:erase(Key, RowDict),
@@ -238,18 +239,19 @@ get_next_row(State) ->
     {Row, State#collector{rows = Rest, counters=Counters1}}.
 
 %% TODO: rectify nil <-> undefined discrepancies
-find_next_key(nil, Dir, RowDict) ->
-    find_next_key(undefined, Dir, RowDict);
-find_next_key(undefined, Dir, RowDict) ->
-    case lists:sort(sort_fun(Dir), dict:fetch_keys(RowDict)) of
+find_next_key(nil, Dir, Collation, RowDict) ->
+    find_next_key(undefined, Dir, Collation, RowDict);
+find_next_key(undefined, Dir, Collation, RowDict) ->
+    CmpFun = fun(A, B) -> compare(Dir, Collation, A, B) end,
+    case lists:sort(CmpFun, dict:fetch_keys(RowDict)) of
     [] ->
         throw(complete);
     [Key|_] ->
         {Key, nil}
     end;
-find_next_key([], _, _) ->
+find_next_key([], _, _, _) ->
     throw(complete);
-find_next_key([Key|Rest], _, _) ->
+find_next_key([Key|Rest], _, _, _) ->
     {Key, Rest}.
 
 transform_row(#view_row{key=Key, id=reduced, value=Value}) ->
@@ -263,11 +265,11 @@ transform_row(#view_row{key=Key, id=_Id, value=_Value, doc={error,Reason}})
->
 transform_row(#view_row{key=Key, id=Id, value=Value, doc=Doc}) ->
     {row, [{id,Id}, {key,Key}, {value,Value}, {doc,Doc}]}.
 
-
-sort_fun(fwd) ->
-    fun(A,A) -> true; (A,B) -> couch_ejson_compare:less_json(A,B) end;
-sort_fun(rev) ->
-    fun(A,A) -> true; (A,B) -> couch_ejson_compare:less_json(B,A) end.
+compare(_, _, A, A) -> true;
+compare(fwd, <<"raw">>, A, B) -> A < B;
+compare(rev, <<"raw">>, A, B) -> B < A;
+compare(fwd, _, A, B) -> couch_ejson_compare:less_json(A, B);
+compare(rev, _, A, B) -> couch_ejson_compare:less_json(B, A).
 
 extract_view(Pid, ViewName, [], _ViewType) ->
     couch_log:error("missing_named_view ~p", [ViewName]),

http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/96fe423a/src/fabric_view_reduce.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view_reduce.erl b/src/fabric_view_reduce.erl
index 8fb5b0b..5f09deb 100644
--- a/src/fabric_view_reduce.erl
+++ b/src/fabric_view_reduce.erl
@@ -23,8 +23,7 @@ go(DbName, GroupId, View, Args, Callback, Acc0, VInfo) when is_binary(GroupId)
-
     {ok, DDoc} = fabric:open_doc(DbName, <<"_design/", GroupId/binary>>, []),
     go(DbName, DDoc, View, Args, Callback, Acc0, VInfo);
 
-go(DbName, DDoc, VName, Args, Callback, Acc, {red, {_, Lang, _}, _}=VInfo) ->
-    RedSrc = couch_mrview_util:extract_view_reduce(VInfo),
+go(DbName, DDoc, VName, Args, Callback, Acc, VInfo) ->
     RPCArgs = [fabric_util:doc_id_and_rev(DDoc), VName, Args],
     Shards = fabric_view:get_shards(DbName, Args),
     Repls = fabric_view:get_shard_replacements(DbName, Shards),
@@ -37,7 +36,7 @@ go(DbName, DDoc, VName, Args, Callback, Acc, {red, {_, Lang, _}, _}=VInfo)
->
         case fabric_util:stream_start(Workers0, #shard.ref, StartFun, Repls) of
             {ok, Workers} ->
                 try
-                    go2(DbName, Workers, Lang, RedSrc, Args, Callback, Acc)
+                    go2(DbName, Workers, VInfo, Args, Callback, Acc)
                 after
                     fabric_util:cleanup(Workers)
                 end;
@@ -58,8 +57,9 @@ go(DbName, DDoc, VName, Args, Callback, Acc, {red, {_, Lang, _}, _}=VInfo)
->
         rexi_monitor:stop(RexiMon)
     end.
 
-go2(DbName, Workers, Lang, RedSrc, Args, Callback, Acc0) ->
-    #mrargs{limit = Limit, skip = Skip, keys = Keys} = Args,
+go2(DbName, Workers, {red, {_, Lang, View}, _}=VInfo, Args, Callback, Acc0) ->
+    #mrargs{limit = Limit, skip = Skip, keys = Keys, direction=Dir} = Args,
+    RedSrc = couch_mrview_util:extract_view_reduce(VInfo),
     OsProc = case os_proc_needed(RedSrc) of
         true -> couch_query_servers:get_os_process(Lang);
         _ -> nil
@@ -75,6 +75,7 @@ go2(DbName, Workers, Lang, RedSrc, Args, Callback, Acc0) ->
         lang = Lang,
         os_proc = OsProc,
         reducer = RedSrc,
+        collation = couch_util:get_value(<<"collation">>, View#mrview.options),
         rows = dict:new(),
         user_acc = Acc0
     },


Mime
View raw message