empty list when running the mapreduce script

Matthew Pflueger matthew.pflueger at gmail.com
Thu May 6 09:38:41 EDT 2010

Hi Norman,

I ran into the same problem when following The Riak Fast Track.  My
problem was that the script actually wasn't importing anything.  I
changed the script as follows which worked.  Maybe it will work for

#!/usr/bin/env escript
main([Filename]) ->
    {ok, Data} = file:read_file(Filename),
    %%Lines = tl(re:split(Data, "\r?\n", [{return, binary},trim])),
    Lines = tl(re:split(Data, "\r\n|\n|\r", [{return, binary},trim])),
    %%lists:foreach(fun(L) -> LS = re:split(L, ","),
format_and_insert(LS) end, Lines).
    AccOut = lists:foldl(fun(L, AccIn) -> LS = re:split(L, ","),
format_and_insert(LS, AccIn), AccIn + 1 end, 1, Lines),
    io:format("Inserted ~w lines~n", [AccOut]).

format_and_insert(Line, AccIn) ->
    JSON = io_lib:format("{\"Date\":\"~s\",\"Open\":~s,\"High\":~s,\"Low\":~s,\"Close\":~s,\"Volume\":~s,\"Adj
Close\":~s}", Line),
    %%Command = io_lib:format("curl -X PUT -d '~s' -H 'content-type:
application/json'", [hd(Line),JSON]),
    Command = io_lib:format("curl -X PUT -d '~s' -H 'content-type:
application/json'", [AccIn,JSON]),
    io:format("Inserting line ~w: ~s~n", [AccIn, hd(Line)]),


More information about the riak-users mailing list