Advanced CouchDB Rotterdam.rb July 2010
-
Upload
sander-van-de-graaf -
Category
Technology
-
view
118 -
download
1
description
Transcript of Advanced CouchDB Rotterdam.rb July 2010
CouchDBrelax
CouchDBrelax
Sander van de Graafsvdgraaf
RELAX...
PERFORM LIKE A PR0N STAR
TOPICS
•NoSQL
• CouchDB in a nutshell
•Querying
•map/reduce
• Fulltext search
• CouchApps
NOSQL
IT’S A MOVEMENT
1998
Carlo Strozzi
NOSQL == Not Only SQL
“[The NoSQL movement] departs from the relational model altogether, it should therefore have been called more appropriately ‘NoREL’, or something to that effect.”
- Carlo Strozzi
CouchDBrelax
NUTSHELL
SPEED
APPEND ONLY
NO REPAIR NEEDED
COMPACTING
HTTP SERVER
CAP
CAP
CouchDB
EVENTUALLY CONSISTENT
CouchDB
FULL REST API
REST
• GET
• PUT
• POST
•DELETE
• COPY
• SELECT
• UPDATE
• INSERT
•DELETE
• ...
JSON{ total_rows: 2, offset: 0, rows: [ { id: '_design/foobar', key: '_design/foobar', value: { rev: '5-982b2fc36835715b2aae54609b5d5f1e' } }, { id: 'f0e1fd96eb6e094f74dda8d949000a6a', key: 'f0e1fd96eb6e094f74dda8d949000a6a', value: { rev: '1-86bca407fce8234a63c90ff549b56b10' } }, ]}
REPLICATION
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
CouchDBrelax
US NL
CouchDBrelax
CouchDBrelax
CouchDBrelax
Laptop Desktop
Phone
P2P WEB
QUERYING
GET /documents/123
SELECT * FROM documents WHERE id = 123
GET /documents/123PUT /documents/123POST /documents/123DELETE /documents/123
etc.
SELECT * FROM documents WHERE id = 123
MAP/REDUCE
INPUT
IP Bytes
212.122.174.13 18271
212.122.174.13 191726
212.122.174.13 198
74.119.8.111 91272
74.119.8.111 8371
212.122.174.13 43
MAPPER => REDUCER
IP Bytes
212.122.174.13
18271
212.122.174.13191726
212.122.174.13198
212.122.174.13
43
74.119.8.11191272
74.119.8.1118371
AFTER REDUCE
IP Bytes
212.122.174.13 210238
74.119.8.111 99643
MAP/REDUCE
SELECT COUNT(foo)FROM documentsWHERE 1GROUP BY foo;
MAP/REDUCE
MAP/REDUCE
function(doc) { emit(doc.foo, doc);}
MAP/REDUCE
MAP/REDUCE
function(keys, values, rereduce) { return sum(values);}
MAP/REDUCE
COUCHDB-LUCENEhttp://github.com/rnewson/couchdb-lucene
CONFIG[external]fti=/path/to/python /path/to/couchdb-lucene/tools/couchdb-external-hook.py
[httpd_db_handlers]_fti = {couch_httpd_external, handle_external_req, <<"fti">>}
http://127.0.0.1:5984> GET /foobar/_design/foobar
_DESIGN
{ _id: '_design/foobar', _rev: '8-03a6bc983c721b1cc0ae4b461326bc31', language: 'javascript', views: { foo: { map: 'function(doc) {\n emit(doc.foo,1);\n}', reduce: 'function(keys, values, rereduce) {return sum(values);}' } }}
_DESIGN
{ _id: '_design/foobar', _rev: '8-03a6bc983c721b1cc0ae4b461326bc31', language: 'javascript', views: { foo: { map: 'function(doc) {\n emit(doc.foo,1);\n}', reduce: 'function(keys, values, rereduce) {return sum(values);}' } }, fulltext: { by_subject: { index:"function(doc) { var ret=new Document(); ret.add(doc.subject); return ret }" }, }}
_DESIGN
function(doc) { var ret=new Document(); ret.add(doc.subject); return ret}
_DESIGN
function(doc) { var result = new Document(); result.add(doc.subject, {"field":"subject", "store":"yes"}); result.add(doc.content, {"field":"subject"}); result.add(new Date(), {"field":"indexed_at"}); return result;}
http://127.0.0.1:5984> GET /foobar/_fti/_design/foo/by_subject?q=foobar
http://127.0.0.1:5984> GET /foobar/_fti/_design/foo/by_subject?q=foobar
COUCHAPPShttp://github.com/couchapp/couchapp
“Distributed, scalable, web applications you say?
omgwtfbbq!?!1!!!11!1!eleven”
_attachments
CouchDBrelax
CouchDBrelax
CouchDBrelax
LISTS
http://127.0.0.1:5984> GET /relax/_design/relax/_list/posts/all/foobarHTTP/1.1 200 OKVary: AcceptTransfer-Encoding: chunkedServer: CouchDB/0.11.0 (Erlang OTP/R13B)Etag: "DZZ19EPLWLHI89K1FOW9DGFT5"Date: Sun, 11 Jul 2010 09:55:42 GMTContent-Type: text/html
<h1>ponies</h1><p>rock!</p>
CouchDBrelax
CouchDBrelax
COUCHDBXhttp://janl.github.com/couchdbx/
Q?