NDBI040: Big Data Management and NoSQL Databases h p://www.ksi.mff.cuni.cz/~svoboda/courses/171-ndbi040/ Prac cal Class 5 Riak Mar n Svoboda svoboda@ksi.mff.cuni.cz 13. 11. 2017 Charles University in Prague, Faculty of Mathema cs and Physics Czech Technical University in Prague, Faculty of Electrical Engineering
Riak Overview RiakKV Highly available distributed key-value store h p://basho.com/products/riak-kv/ Data model Instance ( bucket types) buckets objects Bucket = logical collec on of objects Object = key-value pair with metadata Key is a Unicode string, unique within a bucket Value can be anything (text, binary object, image, ) Each object is also associated with metadata NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 2
CRUD Opera ons HTTP API All the user requests are submi ed as HTTP requests with appropriately selected / constructed methods, URLs, headers, and data URL pa ern of HTTP requests for all the CRUD opera ons / buckets / bucket / keys / key? parameter = value & Op onal parameters (depending on the opera on) NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 3
CRUD Opera ons Basic opera ons on objects Create: or methods Inserts a key-value pair into a given bucket Key is specified manually, or will be generated automa cally Read: method Retrieves a key-value pair from a given bucket Update: method Updates a key-value pair in a given bucket Delete: method Removes a key-value pair from a given bucket NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 4
HTTP API curl tool Allows to transfer data from / to a server using HTTP (or other supported protocols) Op ons, HTTP request method to be used (GET, ), Data to be sent to the server (implies the POST method), Extra headers to be included when sending the request, Prints both headers and (not just) body of a response NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 5
First Steps Remotely connect to our NoSQL server SSH and SFTP access PuTTY and WinSCP on Windows nosql.ms.mff.cuni.cz:42222 Check Riak cluster status And with higher permissions NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 6
Read and Write Opera ons Insert object for a new actor Prefix all the bucket names with your Retrieve the previously inserted actor Examine both response body and headers NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 7
Bucket Opera ons List all the buckets Only buckets with at least one object will be included List all the keys in the bucket of actors Note that this opera on cannot be executed efficiently NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 8
Update and Delete Opera ons Update our actor object Check the updated actor object Use different virtual nodes as well,, Remove the actor object NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 9
Sample Data Insert objects for new actors Put the data into bucket Use content type NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 10
Sample Data Insert objects for new movies Put the data into bucket Use content type once again NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 11
Links and Link Walking Links = directed rela onships between objects / buckets / bucket / keys / key / bucket _, tag _, 1 0 _ / Parameters assumes only a given target bucket considers only a given link tag whether the objects should be included in the result NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 12
Links and Link Walking Create new links actor movie Check the updated actor object Verify the presence of links in par cular Traverse the links from the actor NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 13
Links and Link Walking Add all the links movie actor Express a more complicated link walking query Find all the actors that appeared in movies where Trojan stared NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 14
Search 2.0: Yokozuna Create a full-text index for the bucket of actors Verify the new bucket proper es NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 15
Search 2.0: Yokozuna Reinsert objects for all the actors Note that names of fields were changed Suffixes recognizable by the JSON extractor were added Czech accented characters were removed NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 16
Search 2.0: Yokozuna Find all the actors born in 1964 Express a more complicated full-text query Find all the actors who were born in 1960 or later and their name contains substring de NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 17
References Riak documenta on h p://docs.basho.com/riak/kv/2.1.4/ Search queries (Apache Solr query syntax) h p://docs.basho.com/riak/kv/2.1.4/ developing/usage/search/ h ps://lucene.apache.org/solr/guide/6_6/ the-standard-query-parser.html NDBI040: Big Data Management and NoSQL Databases Prac cal Class 5: Riak 13. 11. 2017 18