sample queries
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 12 Nov 2010 21:05:49 +0000 (22:05 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 12 Nov 2010 21:05:49 +0000 (22:05 +0100)
riak/load_data
riak/query.sh [new file with mode: 0755]
riak/query/first-week.json [new file with mode: 0644]
riak/query/map-high.json [new file with mode: 0644]
riak/query/map-highs-by-month.json [new file with mode: 0644]
riak/query/simple-map.json [new file with mode: 0644]

index fbd295e..ac8bfe1 100755 (executable)
@@ -7,6 +7,6 @@ main([Filename]) ->
 
 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).
diff --git a/riak/query.sh b/riak/query.sh
new file mode 100755 (executable)
index 0000000..f5e459a
--- /dev/null
@@ -0,0 +1,11 @@
+#!/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
diff --git a/riak/query/first-week.json b/riak/query/first-week.json
new file mode 100644 (file)
index 0000000..fd5f4ea
--- /dev/null
@@ -0,0 +1,7 @@
+{"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
diff --git a/riak/query/map-high.json b/riak/query/map-high.json
new file mode 100644 (file)
index 0000000..444c015
--- /dev/null
@@ -0,0 +1,10 @@
+{"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}}]
+}
diff --git a/riak/query/map-highs-by-month.json b/riak/query/map-highs-by-month.json
new file mode 100644 (file)
index 0000000..5d9e20d
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "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}}
+]
+}
diff --git a/riak/query/simple-map.json b/riak/query/simple-map.json
new file mode 100644 (file)
index 0000000..d80c8bc
--- /dev/null
@@ -0,0 +1,6 @@
+{"inputs":"goog",
+  "query":[{"map":{"language":"javascript",
+                   "name":"Riak.mapValuesJson",
+                   "keep":true}}
+          ]
+}
\ No newline at end of file