map-reduce with couchdb - kore nordmann · pdf filemap-reduce with couchdb kore nordmann ...

52
Map-Reduce with CouchDB Kore Nordmann <[email protected]> @koredn March 21, 2010 http://kore-nordmann.de/portfolio.html Kore Nordmann <[email protected]>

Upload: lamdan

Post on 04-Mar-2018

235 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce with CouchDB

Kore Nordmann<[email protected]>

@koredn

March 21, 2010

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 2: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Outline 2 / 42

Our documents

Introduction

Joins

Tree structures

QA

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 3: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Our documents 3 / 42

I Example: Issue tracker bug document

1 { ” i d ” : ” i s s u e −42” ,2 ” type ” : ” i s s u e ” ,3 ” t i t l e ” : ”Bug i n module foo ” ,4 ” t e x t ” : ”Your s o f twa r e suck s ! ” ,5 ” c r e a t o r ” : ” use r−bar ” ,6 ” s t a t e ” : ”new” ,7 ” e d i t e d ” : 1935678239 ,8 . . .9 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 4: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Our documents 4 / 42

I Example: Issue tracker bug comment

1 { ” i d ” : ”80572348 asd fg789342 ” ,2 ” type ” : ” i s s u e−comment ” ,3 ” i s s u e ” : ” i s s u e −42” ,4 ” e d i t e d ” : 1935678239 ,5 ” t e x t ” : ” I second tha t ! ” ,6 . . .7 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 5: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Outline 5 / 42

Our documents

Introduction

Joins

Tree structures

QA

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 6: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-reduce-views 6 / 42

I “MapReduce is a software framework introduced by Google tosupport distributed computing on large data sets on clustersof computers.” [Wik09]

I Used by CouchDB to implement views

I Just a framework / pattern: You can implement “any”algorithm using map-reduce.

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 7: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-reduce-views 6 / 42

I “MapReduce is a software framework introduced by Google tosupport distributed computing on large data sets on clustersof computers.” [Wik09]

I Used by CouchDB to implement views

I Just a framework / pattern: You can implement “any”algorithm using map-reduce.

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 8: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-reduce-views 6 / 42

I “MapReduce is a software framework introduced by Google tosupport distributed computing on large data sets on clustersof computers.” [Wik09]

I Used by CouchDB to implement views

I Just a framework / pattern: You can implement “any”algorithm using map-reduce.

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 9: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 7 / 42

Documents

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 10: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 8 / 42

Documents Map

$key:$value

$key:$value

$key:$value

$key:$value

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 11: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 9 / 42

ReduceDocuments Map

$key:$value

$key:$value

$key:$value

$key:$value

$key:$value

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 12: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 10 / 42

Documents Re-ReduceReduceMap

$key:$value

$key:$value

$key:$value

$key:$value

$key:$value

$key:$value

$key:$value

Cluster 1

Cluster 2

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 13: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 11 / 42

I Map and reduce functions are custom

I Reduce is optional, plain view serves as a document index

I Reduce may be applied to subsets of the documents

I Reduce may be grouped

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 14: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 11 / 42

I Map and reduce functions are custom

I Reduce is optional, plain view serves as a document index

I Reduce may be applied to subsets of the documents

I Reduce may be grouped

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 15: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 11 / 42

I Map and reduce functions are custom

I Reduce is optional, plain view serves as a document index

I Reduce may be applied to subsets of the documents

I Reduce may be grouped

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 16: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce 11 / 42

I Map and reduce functions are custom

I Reduce is optional, plain view serves as a document index

I Reduce may be applied to subsets of the documents

I Reduce may be grouped

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 17: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Our documents 12 / 42

I Example: Issue tracker bug document

1 { ” i d ” : ” i s s u e −42” ,2 ” type ” : ” i s s u e ” ,3 ” t i t l e ” : ”Bug i n module foo ” ,4 ” t e x t ” : ”Your s o f twa r e suck s ! ” ,5 ” c r e a t o r ” : ” use r−bar ” ,6 ” s t a t e ” : ”new” ,7 ” e d i t e d ” : 1935678239 ,8 . . .9 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 18: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 13 / 42

I Count issue states

1 f u n c t i o n ( doc )2 {3 i f ( doc . type == ” i s s u e ” )4 {5 emit ( doc . s t a t e , 1 ) ;6 }7 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 19: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 14 / 42

I The simplest reduce function is just count()I Often used for statistics

1 f u n c t i o n ( keys , v a l u e s , combine )2 {3 re tu rn sum( v a l u e s ) ;4 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 20: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 15 / 42

I The mapping result

1 ”new” => 1 ,2 ” a s s i g n e d ” => 1 ,3 ”new” => 1 ,4 ” c l o s e d ” => 1 ,5 ”new” => 1 ,6 ”new” => 1 ,7 ” c l o s e d ” => 1 ,8 ” a s s i g n e d ” => 1 ,9 ” a s s i g n e d ” => 1 ,

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 21: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 16 / 42

I The reduce result

1 nu l l => 12

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 22: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 17 / 42

I The grouped reduce result

1 ”new” => 5 ,2 ” a s s i g n e d ” => 23 ,3 ” c l o s e d ” => 42 ,

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 23: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Result 18 / 42

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 24: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 19 / 42

I The map function

1 f u n c t i o n ( doc )2 {3 i f ( doc . type == ” w i k i ” )4 {5 date = new Date ( ) ;6 date . setTime ( doc . e d i t e d ∗ 1000 ) ;7 emit ( [8 date . getUTCFul lYear ( ) ,9 date . getUTCMonth ( ) + 1 ,

10 date . getUTCDate ( ) ,11 date . getUTCHours ( ) ,12 date . getUTCMinutes ( ) ,13 date . getUTCSeconds ( ) ,14 ] , 1 ) ;15 // You cou ld a l s o emit the whole doc as v a l u e16 }17 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 25: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 20 / 42

I The mapping result

1 [ 2008 , 10 , 11 , 9 , 11 , 12 ] => 12 [ 2008 , 10 , 11 , 9 , 11 , 12 ] => 13 [ 2008 , 10 , 11 , 9 , 11 , 12 ] => 14 [ 2008 , 10 , 11 , 9 , 13 , 8 ] => 15 [ 2008 , 10 , 11 , 9 , 13 , 44 ] => 16 [ 2008 , 10 , 11 , 9 , 14 , 2 ] => 17 [ 2008 , 10 , 12 , 17 , 46 , 15 ] => 18 [ 2008 , 10 , 12 , 17 , 57 , 52 ] => 19 [ 2008 , 10 , 12 , 18 , 0 , 45 ] => 1

10 [ 2008 , 10 , 14 , 8 , 36 , 29 ] => 111 [ 2008 , 10 , 14 , 19 , 33 , 21 ] => 112 [ 2008 , 10 , 14 , 19 , 33 , 35 ] => 1

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 26: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 21 / 42

I The reduce function

1 f u n c t i o n ( keys , v a l u e s , combine )2 {3 re tu rn sum( v a l u e s ) ;4 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 27: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 22 / 42

I The reduce result

1 nu l l => 12

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 28: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 23 / 42

I The grouped reduce result

1 [ 2008 , 10 , 11 , 9 , 11 , 12 ] => 32 [ 2008 , 10 , 11 , 9 , 13 , 8 ] => 13 [ 2008 , 10 , 11 , 9 , 13 , 44 ] => 14 [ 2008 , 10 , 11 , 9 , 14 , 2 ] => 15 [ 2008 , 10 , 12 , 17 , 46 , 15 ] => 16 [ 2008 , 10 , 12 , 17 , 57 , 52 ] => 17 [ 2008 , 10 , 12 , 18 , 0 , 45 ] => 18 [ 2008 , 10 , 14 , 8 , 36 , 29 ] => 19 [ 2008 , 10 , 14 , 19 , 33 , 21 ] => 1

10 [ 2008 , 10 , 14 , 19 , 33 , 35 ] => 1

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 29: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 24 / 42

I The filtered grouped reduce result

I startkey=[2008,10,11] and endkey=[2008,10,12]

1 [ 2008 , 10 , 11 , 9 , 11 , 12 ] => 32 [ 2008 , 10 , 11 , 9 , 13 , 8 ] => 13 [ 2008 , 10 , 11 , 9 , 13 , 44 ] => 14 [ 2008 , 10 , 11 , 9 , 14 , 2 ] => 1

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 30: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Map-Reduce example 25 / 42

I The grouped reduce result, with group level

I group-level=3

1 [ 2008 , 10 , 11 ] => 62 [ 2008 , 10 , 12 ] => 33 [ 2008 , 10 , 14 ] => 3

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 31: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Result 26 / 42

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 32: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Full-Text-Search 27 / 42

I Index all documents by all their words

1 f u n c t i o n ( doc ) {2 i f ( doc . type == ” i s s u e ” ) {3 // S imple word i ndex i ng , does not r e s p e c t o v e r a l l

o c cu r en c e s o f words ,4 // stopwords , d i f f e r e n t word s e p e r a t i o n c h a r a c t e r s ,

o r word v a r i a t i o n s .5 va r t e x t = doc . t i t l e . r e p l a c e ( / [\ s : . , ! ? − ]+/ g , ” ”

) +6 doc . t e x t . r e p l a c e ( / [\ s : . , ! ? − ]+/ g , ” ” )

;7 va r words = t e x t . s p l i t ( ” ” ) ;8 f o r ( va r i = 0 ; i < words . l e n g t h ; ++i ) {9 v a l u e = {} ;

10 v a l u e [ doc . i d ] = 1 ;11 emit ( words [ i ] . toLowerCase ( ) , v a l u e ) ;12 }13 }14 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 33: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 28 / 42

I Index all documents by all their words

1 . . .2 ”a” => { i s s u e −8: 1}3 ”a” => { i s s u e −8: 1}4 ”a” => { i s s u e −8: 1}5 ”a” => { i s s u e −8: 1}6 ”a” => { i s s u e −81: 1}7 ”a” => { i s s u e −83: 1}8 ”a” => { i s s u e −83: 1}9 ” ab l e ” => { i s s u e −39: 1}

10 ” ab l e ” => { i s s u e −56: 1}11 ” ab l e ” => { i s s u e −73: 1}12 ” ab l e ” => { i s s u e −80: 1}13 ” about ” => { i s s u e −24: 1}14 ” about ” => { i s s u e −43: 1}15 ” about ” => { i s s u e −85: 1}16 . . .

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 34: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Full-Text-Search 29 / 42

I Reduce by word count

1 f u n c t i o n ( keys , v a l u e s ) {2 va r count = {} ;3 f o r ( va r i i n v a l u e s ) {4 f o r ( va r i d i n v a l u e s [ i ] ) {5 i f ( count [ i d ] ) {6 count [ i d ] = v a l u e s [ i ] [ i d ] + count [ i d ] ;7 } e l s e {8 count [ i d ] = v a l u e s [ i ] [ i d ] ;9 }

10 }11 }12 re tu rn count ;13 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 35: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 30 / 42

I Index all documents by all their words

1 . . .2 ”a” => {3 i s s u e −68: 6 ,4 i s s u e −66: 6 ,5 i s s u e −22: 4 ,6 i s s u e −63: 3 ,7 i s s u e −60: 2 ,8 i s s u e −35: 2 ,9 i s s u e −34: 1 ,

10 i s s u e −31: 1 ,11 . . .12 }13 ” ab l e ” => { i s s u e −86: 1 , i s s u e −80: 1 , i s s u e −73: 1 ,

i s s u e −56: 1 , i s s u e −39: 1}14 ” about ” => { i s s u e −85: 1 , i s s u e −43: 1 , i s s u e −24: 1}15 . . .

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 36: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Outline 31 / 42

Our documents

Introduction

Joins

Tree structures

QA

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 37: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Inter document links 32 / 42

I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:

I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)

I Solution depends on update-ratio

1 { ” type ” : ” i s s u e ” ,2 ” t i t l e ” : ” He l l o wor ld ” ,3 ” t e x t ” : ” . . . ” ,4 ”comments ” : [5 { ”comment ” : ” . . . ” } ,6 ] ,7 ” c r e a t o r ” : ” use r−f oo ” ,8 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 38: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Inter document links 32 / 42

I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:

I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)

I Solution depends on update-ratio

1 { ” type ” : ” i s s u e ” ,2 ” t i t l e ” : ” He l l o wor ld ” ,3 ” t e x t ” : ” . . . ” ,4 ”comments ” : [5 { ”comment ” : ” . . . ” } ,6 ] ,7 ” c r e a t o r ” : ” use r−f oo ” ,8 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 39: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Inter document links 32 / 42

I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:

I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)

I Solution depends on update-ratio

1 { ” type ” : ” i s s u e ” ,2 ” t i t l e ” : ” He l l o wor ld ” ,3 ” t e x t ” : ” . . . ” ,4 ”comments ” : [5 { ”comment ” : ” . . . ” } ,6 ] ,7 ” c r e a t o r ” : ” use r−f oo ” ,8 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 40: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Inter document links 32 / 42

I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:

I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)

I Solution depends on update-ratio

1 { ” type ” : ” i s s u e ” ,2 ” t i t l e ” : ” He l l o wor ld ” ,3 ” t e x t ” : ” . . . ” ,4 ”comments ” : [5 { ”comment ” : ” . . . ” } ,6 ] ,7 ” c r e a t o r ” : ” use r−f oo ” ,8 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 41: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Inter document links 32 / 42

I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:

I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)

I Solution depends on update-ratio

1 { ” type ” : ” i s s u e ” ,2 ” t i t l e ” : ” He l l o wor ld ” ,3 ” t e x t ” : ” . . . ” ,4 ”comments ” : [5 { ”comment ” : ” . . . ” } ,6 ] ,7 ” c r e a t o r ” : ” use r−f oo ” ,8 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 42: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Inter document links 32 / 42

I There is no ensured inter document consistency in CouchDBI Different possibilities of relating documents:

I List IDs of related documents in document (n:m)I ... both directions are feasibleI Embed the whole related document (1:n)

I Solution depends on update-ratio

1 { ” type ” : ” i s s u e ” ,2 ” t i t l e ” : ” He l l o wor ld ” ,3 ” t e x t ” : ” . . . ” ,4 ”comments ” : [5 { ”comment ” : ” . . . ” } ,6 ] ,7 ” c r e a t o r ” : ” use r−f oo ” ,8 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 43: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 33 / 42

I JOIN query

1 f u n c t i o n ( doc )2 {3 i f ( doc . type == ” i s s u e ” )4 {5 emit ( [ doc . i d , 0 ] , doc . i d ) ;6 }7

8 i f ( doc . type == ” issue comment ” )9 {

10 emit ( [ doc . i s s u e , doc . i d ] , doc . i d ) ;11 }12 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 44: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 34 / 42

I JOIN query result

1 [ ” t r a c k e r i s s u e −1” , 0 ] => ” t r a c k e r i s s u e −1”2 [ ” t r a c k e r i s s u e −1” , ”1 eaaa503adbec07b0013c060b5d7b53c ” ]

=> ”1 eaaa503adbec07b0013c060b5d7b53c ”3 [ ” t r a c k e r i s s u e −1” , ”6 e77ebd5ea0383c f1d8ed505f2517ca7 ” ]

=> ”6 e77ebd5ea0383c f1d8ed505f2517ca7 ”4 [ ” t r a c k e r i s s u e −1” , ” b0502afb84a80a48fecc7442153c0aa2 ” ]

=> ” b0502afb84a80a48fecc7442153c0aa2 ”5 [ ” t r a c k e r i s s u e −10” , 0 ] => ” t r a c k e r i s s u e −10”6 [ ” t r a c k e r i s s u e −10” , ”63872 cd8a4d5301238dbdb084a4d7a3f ”

] => ”63872 cd8a4d5301238dbdb084a4d7a3f ”7 [ ” t r a c k e r i s s u e −10” , ”9 a f0dd3c4d184c07c2 f f 98982 f98d39 f ”

] => ”9 a f0dd3c4d184c07c2 f f 98982 f98d39 f ”

I Can again be filtered...

I Using “?include docs=true” also gives you all documents(since 0.11)

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 45: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Outline 35 / 42

Our documents

Introduction

Joins

Tree structures

QA

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 46: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Inter document links 36 / 42

1 { ” type ” : ” forum−pos t ” ,2 ” t i t l e ” : ” He l l o wor ld ” ,3 ” t e x t ” : ” . . . ” ,4 ” pa r e n t s ” : [ ” forum−post −23” , ” forum−post −42” ]5 ” c r e a t o r ” : ” use r−f oo ” ,6 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 47: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 37 / 42

I Tree view

1 f u n c t i o n ( doc )2 {3 i f ( doc . type == ”forum−pos t ” )4 {5 l o c a t i o n = doc . p a r e n t s ;6 l o c a t i o n . append ( doc . i d ) ;7 emit ( l o c a t i o n , doc . i d ) ;8 }9 }

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 48: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 38 / 42

I Tree query result

1 [ ” forum−post−1” ]2 => ” forum−post−1”3 [ ” forum−post−1” , ” forum−post−2” ]4 => ” forum−post−2”5 [ ” forum−post−1” , ” forum−post−2” , ” forum−post−4” ]6 => ” forum−post−4”7 [ ” forum−post−1” , ” forum−post−3” ]8 => ” forum−post−3”

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 49: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Issue tracker 39 / 42

I Tree query subtree result

I startkey=["forum-post-1", "forum-post-2"]

1 [ ” forum−post−1” , ” forum−post−2” ]2 => ” forum−post−2”3 [ ” forum−post−1” , ” forum−post−2” , ” forum−post−4” ]4 => ” forum−post−4”

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 50: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Outline 40 / 42

Our documents

Introduction

Joins

Tree structures

QA

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 51: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

The end 41 / 42

I Open questions?

I Further remarks?I Contact

I Mail: <[email protected]>I Web: http://kore-nordmann.de/ (Slides will be available

here soonish)I Twitter: http://twitter.com/koredn

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>

Page 52: Map-Reduce with CouchDB - Kore Nordmann · PDF fileMap-Reduce with CouchDB Kore Nordmann  @koredn March 21, 2010   Kore Nordmann

Bibliography I 42 / 42

[Wik09] Wikipedia, Mapreduce — wikipedia, the free encyclopedia, 2009,[Online; accessed 27-August-2009].

http://kore-nordmann.de/portfolio.html

Kore Nordmann <[email protected]>