2014-08-30 66 views
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...\\"},...]},...]"}' 

,當我在我的本地機器上運行我沒有得到的錯誤,但是當我在服務器I運行圖,減少階段我得到的錯誤。

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]. 

的數據,當我運行上面的減少相映射階段我得到在我的本地設置是像下面

[{'[email protected]': {'ab_leads': 2, 'cp_leads': 1}, 
'[email protected]': {'ab_leads': 0, 'cp_leads': 1}}] 

但我得到錯誤,當我執行相同的錯誤在服務器上,請幫助我

回答

2

你會得到一個function_clause錯誤,因爲你傳遞給fun倍數永遠不會匹配列表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). 
+0

thanks @seancribbs,但我自己解決了它 – 2014-12-26 11:00:45