format_and_insert(Line) ->
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 http://127.0.0.1:8091/riak/goog/~s -d '~s' -H 'content-type: application/json'", [hd(Line),JSON]),
+ Command = io_lib:format("curl -X PUT http://192.168.1.200:8098/riak/goog/~s -d '~s' -H 'content-type: application/json'", [hd(Line),JSON]),
io:format("Inserting: ~s~n", [hd(Line)]),
os:cmd(Command).
--- /dev/null
+#!/bin/sh -x
+
+function execute_query {
+ curl -v -X POST http://192.168.1.200:8098/mapred -H "Content-Type: application/json" -d @$1
+}
+
+ls query/*.json | while read file ; do
+ echo "executing $file"
+ execute_query $file
+ echo
+done
--- /dev/null
+{"inputs":[["goog","2010-01-04"],
+ ["goog","2010-01-05"],
+ ["goog","2010-01-06"],
+ ["goog","2010-01-07"],
+ ["goog","2010-01-08"]],
+ "query":[{"map":{"language":"javascript","name":"Riak.mapValuesJson","keep":true}}]
+}
\ No newline at end of file
--- /dev/null
+{"inputs":[["goog","2010-01-04"],
+ ["goog","2010-01-05"],
+ ["goog","2010-01-06"],
+ ["goog","2010-01-07"],
+ ["goog","2010-01-08"]],
+ "query":[{"map":{"language":"javascript",
+ "source":"function(value,keyData,arg){ var data = Riak.mapValuesJson(value)[0]; return [data.High];}"
+ }},
+ {"reduce":{"language":"javascript","name":"Riak.reduceMax","keep":true}}]
+}
--- /dev/null
+{
+ "inputs":"goog",
+ "query":[
+ {"map":{"language":"javascript", "source":"function(value, keyData, arg){ var data = Riak.mapValuesJson(value)[0]; var month = value.key.split('-').slice(0,2).join('-'); var obj = {}; obj[month] = data.High; return [obj];}"}},
+ {"reduce":{"language":"javascript", "source":"function(values, arg){ return [ values.reduce(function(acc, item){ for(var month in item){ if(acc[month]) { acc[month] = (acc[month] < item[month]) ? item[month] : acc[month]; } else { acc[month] = item[month]; } } return acc; })];}", "keep":true}}
+]
+}
--- /dev/null
+{"inputs":"goog",
+ "query":[{"map":{"language":"javascript",
+ "name":"Riak.mapValuesJson",
+ "keep":true}}
+ ]
+}
\ No newline at end of file