Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Riak Query Tale

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
Mathias Meyer
February 01, 2012

A Riak Query Tale

An introduction to the abundance of ways you can get data out of Riak.

Mathias Meyer

February 01, 2012

Transcript

63 slides
  1. MapReduce  var  nameLength  =  function(value)  {      var  doc

     =  Riak.mapValues(value)[0];      return  [doc.length];  }
  2. MapReduce  riak.add("users").            map(nameLength).    

           reduce("Riak.reduceSum").            run()
  3. MapReduce  var  average  =  function(values)  {      var  avg

     =  values.reduce(function(n,  sum)  {          return  sum  +=  n;      },  0);      return  [(avg  /  values.length)];  }
  4. MapReduce  riak.add("users").            map(nameLength).    

           reduce(average).            run()
  5. MapReduce  riak.add("users").            map(nameLength).    

           reduce(average).            run() Uh-Oh!
  6. MapReduce  riak.add(["users",  "roidrage"]).            map(nameLength).  

             reduce(average).            run() Better!
  7. MapReduce  riak.add('tweets').    map({language:  'erlang',          

               module:  'riak_kv_mapreduce',                      function:  'map_object_value'}).run()  
  8. MapReduce  ExtractFirstName1  =  fun(RObject,  _,  _)  -­‐>      

                                 Value  =  riak_object:get_value(RObject),                                    [FirstName,  _]  =  re:split(Value,  "  "),                                      [FirstName]                                                                                        end.
  9. MapReduce  C:mapred([{<<"users">>,  <<"roidrage">>}],              

                         [{map,  {qfun,  ExtractFirstName},  none,  true}]).
  10. Key-Filters  riak.add({bucket:  'users',  key_filters:            

     [["and",  [["string_to_int"],                                  ["less_than",  10]],                                [["string_to_int"],                                  ["greater_than",  5]]]]})
  11. Riak 2i  curl  -­‐X  PUT  .../riak/users/roidrage  -­‐d  @-­‐  \  

             -­‐H  "Content-­‐Type:  text/plain"  \            -­‐H  "X-­‐Riak-­‐Index-­‐firstname_bin:  mathias"  \            -­‐H  "X-­‐Riak-­‐Index-­‐lastname_bin:  meyer"  
  12. MapReduce  riak.add({bucket:  'users',              

           index:  'lastname_bin',                      key:  'mathias'}).            map('Riak.mapValuesJson').run()  
  13. Riak 2i No Multi-Index Queries Requires Extra Work in the

    App Returns only keys Document-partitioned
  14. Riak Search  curl  -­‐X  PUT  localhost:8098/riak/users  -­‐d  @-­‐  \  

             -­‐H  "Content-­‐Type:  application/json"  {"props":{"precommit":  [{"mod":"riak_search_kv_hook","fun":"precommit"}  ]}}
  15. Indexing Riak Objects  curl  -­‐X  PUT  .../riak/users/roidrage  \    

           -­‐d  "Mathias  Meyer"            -­‐H  "Content-­‐Type:  text/plain"
  16. Riak Search Full text search of structured data Term-partitioned Efficient

    for one term queries Multiple Interfaces No Anti-Entropy

More Decks by Mathias Meyer

Other Decks in Programming