Guest User

Untitled

a guest
Feb 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. require 'rubygems'
  2. require 'riak'
  3. require 'json'
  4. require 'benchmark'
  5. require 'pp'
  6.  
  7. $client = Riak::Client.new :protocol => :pbc
  8.  
  9. def latest_10_via_values
  10. mr = Riak::MapReduce.new($client).
  11. add("events").
  12. map(<<-MAP).
  13. function(v) {
  14. var data = Riak.mapValuesJson(v)[0]
  15. var epoch_ms = parseInt(data.created_at, 16);
  16. return [ { time : epoch_ms, key : v.key } ];
  17. }
  18. MAP
  19. reduce(<<-REDUCE, :keep => true)
  20. function(vs) {
  21. var vs_sorted = vs.sort(function(a,b){ return b.time - a.time; });
  22. return vs_sorted.slice(0,10);
  23. }
  24. REDUCE
  25.  
  26. results = mr.run
  27. puts results
  28. end
  29.  
  30. puts Benchmark.measure { latest_10_via_values }
Add Comment
Please, Sign In to add comment