Webinar
Aug 8 2013
What‘s new in Neo4j 2.0
Michael Hunger, Neo Technology
@mesirii | @neo4j
BIG NEWS
Neo4j 2.0.0-M04 released today!
Neo4j 2.0
Why 2.0?
(0.x) --> (1.x) --> (2.x)
• 0.x was about embedded java
• 1.x introduced indexes, the server and REST
• 2.x ease of use, big data, cloud
which means a focus on...
This guy
Focus on Cypher
• Cypher, a carefully crafted language for working with graphs
• Declarative, friendly, easy to read and write
• One language, used everywhere
• REST for management, Java for extensions
What is new in 2.0?
Introducing: Node Labels
WORKS_WITH
Person
Employee
Developer
Husband
NoSQL
GraphDB
Database
Awesome!
No Schema is good
Some Structure is helpful
• Simply: a label identifies a set of nodes
• Nodes can have multiple labels
• Find nodes by label
• Constrain properties and values
(lightweight, optional schema)
• A simple idea, with powerful applications
Introducing Node Labels
NoSQL
GraphDB
Database
Awesome!
How to use labels?
Labels - how to use?
• To identify nodes
• To categorize, tag
• To represent types
• To avoid confusion
• For special nodes (domain specific reference nodes)
Labels - rules of thumb
• Use a label to make queries easier to read & write
• And to improve performance through indexing
• Start with anything you might've put in a legacy index
• Use lightly, as few labels as needed
Find friends who like cheese
MATCH (p:Person)-[:FRIENDS]->(friend:Person),
(friend) -[:LIKE]-> (thing:Thing)
WHERE p.name = "Max De Marzi"
AND thing:Food AND thing.name = "Cheese"
RETURN thing, labels(thing);
Schema Indexing
• Indexes for labels, based on a property
• Simple lookups for now
• Unique indexing coming soon
• Full-text, other special indexes in planning
CREATE INDEX ON :Person(name)
MATCH (p:Person)
WHERE p.name = „Max“
RETURN p
MERGE operation
• a combination of MATCH + CREATE
• replaces CREATE UNIQUE (currently still limited)
• attempts to MATCH, with specified properties and labels
• if match fails, new graph data is created
• optional sub-clauses for handling ON CREATE, and ON MATCH
MERGE (p:Person { name:'Charlie Sheen', age:10 })
ON CREATE p SET p.created = timestamp()
RETURN p
Hands-On Cypher
• Migrate Cineasts dataset to use Labels
• Show MATCH on Labels and Properties (+ profile)
• Add an Index on :Person(name) :Movie(title)
• Show MATCH on Labels and Properties (+ profile)
• Show MERGE with a user
https://gist.github.com/jexp/6193139#file-setup-start-sh
https://gist.github.com/jexp/6193139#file-upgrade-movie-database-to-2-0-cql
Demo
Anything else?
• Breaking changes to some APIs (read CHANGES.txt)
• Migration of "legacy" indexes (stop STARTing)
• Mandatory transactions for all DB interactions
• Improving installers (in progress)
• Changing everything to be "all Cypher, all the time"
Cypher Changes: Properties
• no schema -> what happens when properties don‘t exist
• has(n.prop) AND n.prop=“Foobar“
• there was syntactic sugar n.prop! and n.prop?
• now n.prop returns NULL covers n.prop! =“Foobar“
• explicit expression for n.prop? = „Foobar“
WHERE n.name = „Chris“
AND (not(m.name) OR m.name=“Andres“)
Cypher Changes: REMOVE
• consistent remove operations of labels and properties
• you REMOVE attributes (properties, labels)
• and DELETE elements (nodes, relationships)
REMOVE n.name
REMOVE n:People
DELETE node
DELETE relationship
Cypher Changes: Separators
• grammar has to be unambiguous
• extract(n in nodes:Foo)???
• confuse colon from label and collection function separator
• exchanged colon for pipe
EXTRACT (n in nodes | n.name)
FILTER (n in nodes | n.name =~ „And.*“)
FOREACH (v in names | CREATE ( {name: v} ))
Demo
Mandatory Transactions
• we had optional transactions for reads
• Issues:
• In which context do I read?
• Do I read what I read?
• Which changes do I see?
• NOW: Mandatory Transactions for reads and writes!
• only affects embedded API
• Cypher and REST-API take care of their transactions
• begin, commit, or rollback a transaction
• transaction as RESTful resource
• issue multiple statements per request
• multiple requests per transaction
• compact response format
• some driver already support it (neography, jdbc)
Transactional Cypher
Hands-On 2.0
• Show Transactional HTTP-Endpoint
• POST initial statements, look at result, check currently running tx in
server-info
• POST another create statement to the tx
• POST a new read statement to a new tx that shows isolation
• DELETE second transaction
• POST to COMMIT resource
https://gist.github.com/jexp/6193139#file-demo-transactional-endpoint-js
What is new in 2.0?
• It's all about Cypher, starting with
• Labels, the first significant change in over 12 years
• Mix in schema indexing
• Then transactional REST, new clauses, functions
• A fresh Web UI that is Cypher-focused
Thanks :)
MATCH (you)-[:HAVE]->(q:Question)
RETURN q.text
@neo4j or @mesirii to keep in touch

Webinar: What's new in Neo4j 2.0

  • 1.
    Webinar Aug 8 2013 What‘snew in Neo4j 2.0 Michael Hunger, Neo Technology @mesirii | @neo4j
  • 2.
    BIG NEWS Neo4j 2.0.0-M04released today!
  • 3.
  • 4.
  • 5.
    (0.x) --> (1.x)--> (2.x) • 0.x was about embedded java • 1.x introduced indexes, the server and REST • 2.x ease of use, big data, cloud which means a focus on...
  • 6.
  • 7.
    Focus on Cypher •Cypher, a carefully crafted language for working with graphs • Declarative, friendly, easy to read and write • One language, used everywhere • REST for management, Java for extensions
  • 8.
    What is newin 2.0?
  • 9.
  • 10.
  • 11.
    • Simply: alabel identifies a set of nodes • Nodes can have multiple labels • Find nodes by label • Constrain properties and values (lightweight, optional schema) • A simple idea, with powerful applications Introducing Node Labels NoSQL GraphDB Database Awesome!
  • 12.
    How to uselabels?
  • 13.
    Labels - howto use? • To identify nodes • To categorize, tag • To represent types • To avoid confusion • For special nodes (domain specific reference nodes)
  • 14.
    Labels - rulesof thumb • Use a label to make queries easier to read & write • And to improve performance through indexing • Start with anything you might've put in a legacy index • Use lightly, as few labels as needed
  • 15.
    Find friends wholike cheese MATCH (p:Person)-[:FRIENDS]->(friend:Person), (friend) -[:LIKE]-> (thing:Thing) WHERE p.name = "Max De Marzi" AND thing:Food AND thing.name = "Cheese" RETURN thing, labels(thing);
  • 16.
    Schema Indexing • Indexesfor labels, based on a property • Simple lookups for now • Unique indexing coming soon • Full-text, other special indexes in planning CREATE INDEX ON :Person(name) MATCH (p:Person) WHERE p.name = „Max“ RETURN p
  • 17.
    MERGE operation • acombination of MATCH + CREATE • replaces CREATE UNIQUE (currently still limited) • attempts to MATCH, with specified properties and labels • if match fails, new graph data is created • optional sub-clauses for handling ON CREATE, and ON MATCH MERGE (p:Person { name:'Charlie Sheen', age:10 }) ON CREATE p SET p.created = timestamp() RETURN p
  • 18.
    Hands-On Cypher • MigrateCineasts dataset to use Labels • Show MATCH on Labels and Properties (+ profile) • Add an Index on :Person(name) :Movie(title) • Show MATCH on Labels and Properties (+ profile) • Show MERGE with a user https://gist.github.com/jexp/6193139#file-setup-start-sh https://gist.github.com/jexp/6193139#file-upgrade-movie-database-to-2-0-cql
  • 19.
  • 20.
    Anything else? • Breakingchanges to some APIs (read CHANGES.txt) • Migration of "legacy" indexes (stop STARTing) • Mandatory transactions for all DB interactions • Improving installers (in progress) • Changing everything to be "all Cypher, all the time"
  • 21.
    Cypher Changes: Properties •no schema -> what happens when properties don‘t exist • has(n.prop) AND n.prop=“Foobar“ • there was syntactic sugar n.prop! and n.prop? • now n.prop returns NULL covers n.prop! =“Foobar“ • explicit expression for n.prop? = „Foobar“ WHERE n.name = „Chris“ AND (not(m.name) OR m.name=“Andres“)
  • 22.
    Cypher Changes: REMOVE •consistent remove operations of labels and properties • you REMOVE attributes (properties, labels) • and DELETE elements (nodes, relationships) REMOVE n.name REMOVE n:People DELETE node DELETE relationship
  • 23.
    Cypher Changes: Separators •grammar has to be unambiguous • extract(n in nodes:Foo)??? • confuse colon from label and collection function separator • exchanged colon for pipe EXTRACT (n in nodes | n.name) FILTER (n in nodes | n.name =~ „And.*“) FOREACH (v in names | CREATE ( {name: v} ))
  • 24.
  • 25.
    Mandatory Transactions • wehad optional transactions for reads • Issues: • In which context do I read? • Do I read what I read? • Which changes do I see? • NOW: Mandatory Transactions for reads and writes! • only affects embedded API • Cypher and REST-API take care of their transactions
  • 26.
    • begin, commit,or rollback a transaction • transaction as RESTful resource • issue multiple statements per request • multiple requests per transaction • compact response format • some driver already support it (neography, jdbc) Transactional Cypher
  • 27.
    Hands-On 2.0 • ShowTransactional HTTP-Endpoint • POST initial statements, look at result, check currently running tx in server-info • POST another create statement to the tx • POST a new read statement to a new tx that shows isolation • DELETE second transaction • POST to COMMIT resource https://gist.github.com/jexp/6193139#file-demo-transactional-endpoint-js
  • 28.
    What is newin 2.0? • It's all about Cypher, starting with • Labels, the first significant change in over 12 years • Mix in schema indexing • Then transactional REST, new clauses, functions • A fresh Web UI that is Cypher-focused
  • 29.
    Thanks :) MATCH (you)-[:HAVE]->(q:Question) RETURNq.text @neo4j or @mesirii to keep in touch