[erlang-questions] Reduce phase in erlang

Gopi Krishna gopi@REDACTED
Tue Aug 5 14:24:47 CEST 2014


Hi,

I am working on riak database ,

I am having data in a riak bucket for a key like:

<<"{\"META\": {\"campaign\": \"5IVUPHE42HP1NEYvKb7qSvpX2Cm\",
          \"createdat\": 1406978070.0,
          \"user_email\": \"gopikrishnajonnada@REDACTED\"},
 \"mode\": 2,
 \"status\": \"success\"}">>

I have written a map phase which is giving data like

[<<"{<<"5IVUPHE42HP1NEYvKb7qSvpX2Cm">>,1}">>,
<<"{<<"WL6iHLCgs492rFEFvqewzvCfFfj">>, 2}">>,
<<"{"5IVUPHE42HP1NEYvKb7qSvpX2Cm">>, 1}">>,
<<"{<<"5IVUPHE42HP1NEYvKb7qSvpX2Cm">>, 2}">>]

so for the above data from mapphase i have to write a reduce phase that
should give depending on a condition like if it {key,Vlaue} if value is 0
or 1 then i have to to add new variable like ab_leads and it should
increment

I have tried like this this but the reducefunction should have more number
of functions according to [oldlist++newlist]

 <http://chat.stackoverflow.com/transcript/message/18089061#18089061>
lists:foldl(fun({Key,Mode},Acc) -> if Mode == 0;Mode == 1 ->
orddict:update_counter({Key,<<"ab_leads">>},1,Acc); true ->
orddict:update_counter({Key,<<"cp_leads">>},1,Acc) end end,orddict:new(),G).


[{{Key,{<<"ab_leads">>,10},{<<"cp_leads">>,20}},{Key1,{{<<"ab_leads">>,15},{<<"cp_leads">>,15}}].


please suggest me


-- 

Thanks & Regards,
J.Gopi Krishna
+91-8341452934,
www.lintelindia.com
Lintel Technologies Pvt. LTD,Hyderabad.

This message contains confidential information and is intended for
recipient. If you are not the intended recipient you are notified that
disclosing, copying, distributing or taking any action in reliance on the
contents of this information is strictly prohibited. E-mail transmission
cannot be guaranteed to be secure or error-free as information could be
intercepted, corrupted, lost, destroyed, arrive late or incomplete, or
contain viruses. The sender therefore does not accept liability for any
errors or omissions in the contents of this message, which arise as a
result of e-mail transmission. If verification is required please request a
hard-copy version.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140805/9747049a/attachment.htm>


More information about the erlang-questions mailing list