redis graph - amazon s3€¦ · spo:jerry seinfeld:friend:cosmo kramer spo:jerry...

34
Redis Graph A graph database built on top of redis

Upload: others

Post on 03-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Redis GraphA graph database built on top of redis

Page 2: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Open source in-memory database

Key => Data Structure server

Key features: Fast, Flexible, Simple

What’s Redis?

Page 3: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

A Lego for your database

Key

"I'm a Plain Text String!"

{ A: “foo”, B: “bar”, C: “baz” }

Strings/Blobs/Bitmaps

Hash Tables (objects!)

Linked Lists

Sets

Sorted Sets

Geo Sets

HyperLogLog

{ A , B , C , D , E }

[ A → B → C → D → E ]

{ A: 0.1, B: 0.3, C: 100, D: 1337 }

{ A: (51.5, 0.12), B: (32.1, 34.7) }

00110101 11001110 10101010

Page 4: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Node

“Jerry Seinfeld”: {First_Name: “Jerry”,Age: 62

}

Jerry Seinfeld

Page 5: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Relations

Jerry BerlinVisit

Page 6: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

SPOSOPOPSOSPPSOPOS

Hexastore

SSubject

PPredicate

OObject

6

Page 7: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

HexastoreTriplets

SPO:Jerry:Visit:BerlinSOP:Jerry:Berlin:VisitOPS:Berlin:Visit:JerryOSP:Berlin:Jerry:VisitPSO:Visit:Jerry:BerlinPOS:Visit:Berlin:Jerry

JerryS

BerlinO

Visit

P

Page 8: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Places Jerry been to?SPO:Jerry:Visit:*

Who visited Berlin?OPS:Berlin:Visit:*

Who travels and to where?PSO:Visit:*

Hexastore

JerryS

BerlinO

Visit

P

Page 9: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Cypher*

MATCH (Jerry:’Jerry Seinfeld’)-[friend]->(F)-[visit]->(country)

WHERE (F.age >= Jerry.age AND country.continent = ‘Europe’)

RETURN F.name, count(country.name) AS countriesVisited

ORDER BY countriesVisited, F.age DESC

LIMIT 2

Query language

Page 10: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Tokenizer - Lex

Parser - Lemon, SQLite LALR(1) parser generator for C

opencypher

Query language

Page 11: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to endMATCH (Jerry:’Jerry Seinfeld’)-[friend]->(F)-[visit]->(Country)

WHERE F.age >= 50 AND Country.continent = “Europe”

RETURN F.name, F.age, Country.name

ORDER BY F.age DESC

LIMIT 5

Page 12: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

LexerQuery Parser AST

Page 13: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to endAST

Root

Match Where Return Order

Page 14: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to endMATCH (Jerry:"Jerry Seinfeld")-[friend]->(F)-[visit]->(Country)

Alias: Jerry

ID: Jerry Seinfeld

Alias: FID: ?

Alias: Country

ID: ?visitfriend

Page 15: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

Alias: Jerry

ID: Jerry Seinfeld

Alias: FID: ?

Alias: Country

ID: ?visitfriend

SPO:Jerry Seinfeld:friend:*

SPO:Jerry Seinfeld:friend:Cosmo KramerSPO:Jerry Seinfeld:friend:George Costanza

Page 16: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

Alias: Jerry

ID: Jerry Seinfeld

Alias: FID:

Cosmo Kramer

Alias: Country

ID: ?visitfriend

Page 17: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to endWHERE F.age >= 50 AND Country.continent = “Europe”

AND

age >= 50

continent =

“Europe”

Filter tree

Page 18: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

AND

Kramer.age >=

50

continent =

“Europe”

Cosmo Kramer: {Name: ‘Cosmo Kramer’,Age: 48

}

Page 19: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

AND

Kramer.age >=

50

F

continent =

“Europe”

Cosmo Kramer: {Name: ‘Cosmo Kramer’,Age: 48

}

Page 20: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

ANDF

Kramer.age >=

50

F

continent =

“Europe”

Cosmo Kramer: {Name: ‘Cosmo Kramer’,Age: 48

}

Page 21: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

Alias: Jerry

ID: Jerry Seinfeld

Alias: FID: ?

Alias: Country

ID: ?visitfriend

SPO:Jerry Seinfeld:friend:*

SPO:Jerry Seinfeld:friend:Cosmo KramerSPO:Jerry Seinfeld:friend:George Costanza

Page 22: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

Alias: Jerry

ID: Jerry Seinfeld

Alias: FID:

George Costanza

Alias: Country

ID: ?visitfriend

Page 23: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

AND

George.age >=

50

continent =

“Europe”

George Costanza:{Name: ‘George Costanza’,Age: 52

}

Page 24: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

AND

George.age >=

50

T

continent =

“Europe”

George Costanza:{Name: ‘George Costanza’,Age: 52

}

Page 25: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

ANDT

George.age >=

50

T

continent =

“Europe”

T

George Costanza:{Name: ‘George Costanza’,Age: 52

}

Page 26: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

Alias: Jerry

ID: Jerry Seinfeld

Alias: FID:

George Costanza

Alias: Country

ID: ?visitfriend

SPO:George Costanza:visit:*

SPO:George Costanza:visit:ItalySPO:George Costanza:visit:Cuba

Page 27: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

Alias: Jerry

ID: Jerry Seinfeld

Alias: FID:

George Costanza

Alias: CountryID: Italyvisitfriend

Page 28: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to end

ANDT

George.age >=

50

T

Italy.continent

= “Europe”

T

George Costanza:{Name: ‘George Costanza’,Age: 52

}

Italy: {Continent: ‘Europe’,Population: 1000,Name: ‘Italy’

}

Page 29: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

End to endTOP K heap

RETURN F.name, F.age, Country.nameORDER BY F.age DESCLIMIT 5

[‘George Costanza’, 52, Italy]

Page 30: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

FeaturesMulti hop, multi entry point (A)-[R1]->(C)<-[R2]-(B)

(Nicolas:’Nicolas Cage’)-[act]->(Movie)<-[act]-(Actor)

Aggregations, Group bys RETURN F.gender, AVG(F.age) AS average_age

Order bys, Distinct

Page 31: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Benchmark150K inserts per second

15K simple queries per second

Page 32: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

There’s still work to be done● Single node query: MATCH (A) RETURN A● OPTIONAL MATCH● WITH, SKIP, UNION● Curly brackets filters (john {name: ‘John’})● In place evaluations WHERE Me.age > F.age + X● Shortest path between nodes (A)-[*]-(B)● A number of aggregation functions: stdev, precentileCount

Page 33: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Roadmap● Hexastore sorted-set -> Trie● Indexed entities● Single node query● Python lib

Page 34: Redis Graph - Amazon S3€¦ · SPO:Jerry Seinfeld:friend:Cosmo Kramer SPO:Jerry Seinfeld:friend:George Costanza. End to end Alias: Jerry ID: Jerry Seinfeld Alias: F ID: Cosmo Kramer

Contribute/Contact

https://github.com/swilly22/redis-module-graph

@roilipman