Search code examples
sqlmapreduceriak

How to write riak query in riakc


I am a noob at riak, and have been trying to test the query aspect of riak using riakc in erlang. but I can not find any example of how to query the database that match the old SQL way, Only on how to get a single value out of a single field. I think I am missing something but all I really want is just a standard SQL query with a matching riakc code.

SELECT * FROM bucket;

SELECT * FROM bucket LIMIT 10, 100; 

SELECT id, name FROM bucket;

SELECT * FROM bucket WHERE name="john" AND surname LIKE "Ste%";

SELECT * FROM bucket LEFT JOIN bucket2 ON bucket.id = bucket2.id2; 

I assume that there is no direct correlation on how you write these, but was hoping there is a standard way, and is there somewhere that has a a simple to understand way of explaining this querys in riakc (or even just riak).

I have looked a mapreduce but found that it was confusing for just simple queries


Solution

  • Riak is a NoSQL database, more specifically a key-value database, and there is no query language like SQL available. When working with Riak you need to model and query your data in a completely different way compared to how you use a relational database in order to get the most from it. Trying to model and query your data in a relational manner, e.g. by extensive use of secondary indexes or by trying to use map/reduce as a real-time query language, generally results in very poor performance and scalability. A good and useful discussion about Riak development anti-patterns that can be found here.