1

为了这

 Error running MapReduce operation. Headers: {'content-length': '688', 'server': 'MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)', 'connection': 'close', 'date': 'Sat, 30 Aug 2014 14:39:59 GMT', 'content-type': 'application/json', 'http_code': 500} Body: '{"phase":1,"error":"function_clause","input":"[{<<\\"5ItqEz0wfkVWSp9YbFhw5vwETFL\\">>,[{<<\\"ab_leads\\">>,1},{<<\\"cp_leads\\">>,0}]}]","type":"error","stack":"[{report_reduce_totalchatcount,\'-reduce_totalchatcount/2-fun-0-\',[[{<<\\"5ItqEz0wfkVWSp9YbFhw5vwETFL\\">>,[{<<\\"ab_leads\\">>,17},{<<\\"cp_leads\\">>,1}]},{<<\\"YuqlGCpn1MS5eMUN13RJkWSqHjj\\">>,[{<<\\"ab_leads\\">>,2},{<<\\"cp_leads\\">>,0}]}],[]],[{file,\\"report_reduce_totalchatcount.erl\\"},{line,17}]},{lists,foldl,3,[{file,\\"lists.erl\\"},{line,1197}]},{report_reduce_totalchatcount,reduce_totalchatcount,2,[{file,\\"report_reduce_totalchatcount.erl\\"},{line,17}]},{riak_kv_w_reduce,reduce,3,[{file,\\"src/riak_kv_w_reduce.e...\\"},...]},...]"}'

当我在本地机器上运行时,我没有收到错误,但是当我在服务器上运行 map 和 reduce 阶段时,我收到了错误。

减少阶段看起来像这样

-export([reduce_totalchatcount/2]).

reduce_totalchatcount(L,_Arg) ->

Value =   lists:foldl(fun([{Key,[{C,Ab_leads},{A,Cp_leads}]}], Acc) ->
              [{C,Ab_leadsAcc},{A,Cp_leadsAcc}] = proplists:get_value(Key, Acc, [{C,0},{A,0}]),
                  [{Key,[{C,Ab_leadsAcc + Ab_leads},{A,Cp_leadsAcc + Cp_leads}]} | proplists:delete(Key, Acc)]
                  end,
              [],
        L),

[Value].

当我使用 map 阶段运行上述 reduce 阶段时,我得到的数据在我的本地设置中,如下所示

[{'xxxx@gmail.com': {'ab_leads': 2, 'cp_leads': 1},
'xxxx@gmail.com': {'ab_leads': 0, 'cp_leads': 1}}]

但是当我在服务器上执行相同的错误时出现错误,请帮助我

4

1 回答 1

2

您收到function_clause错误消息,因为fun您传递给 fold 永远不会匹配 list 中的项目L。我试图在下面解释和重构您的代码。

-export([reduce_totalchatcount/2]).

fold_total_chatcount({Key, Props}, Acc) ->
    %% I'm not assuming here that the keys in the Props are in any
    %% particular order. The main action of the fold is to find any
    %% existing key that matches and merge its props with this one.
    case lists:keytake(Key, 1, Acc) of
        {value, {_, Props1}, Acc1} ->
            %% Merge props with the found key
            [{Key, merge(Props, Props1)}|Acc1];
        false ->
            %% It doesn't exist so we can just add it to the Acc
            [{Key, Props}|Acc]
    end.

merge(Props1, Props2) ->
    %% See http://www.erlang.org/doc/man/orddict.html#from_list-1 and
    %% http://www.erlang.org/doc/man/orddict.html#merge-3
    orddict:merge(fun(_, V1, V2) -> V1 + V2 end,
                  orddict:from_list(Props1),
                  orddict:from_list(Props2)).

reduce_total_chatcount(L, _Arg) ->
    %% Since lists:foldl/3 is returning a list here, we don't
    %% need to return it wrapped in a list.
    lists:foldl(fun fold_total_chatcount/2, [], L).
于 2014-09-01T16:58:32.667 回答