Skip to content

Instantly share code, notes, and snippets.

View vladbatushkov's full-sized avatar
🥥
Sabai sabai

Vlad Batushkov vladbatushkov

🥥
Sabai sabai
View GitHub Profile
MATCH (g:Genius)
MATCH (art:Artwork)
WITH count(art) as art_total, g
MATCH (inv:Invention)
WITH count(inv) as inv_total, art_total, g
RETURN g.name, art_total as artworks, inv_total as inventions
@vladbatushkov
vladbatushkov / omgc-may-3-1.cypher
Created May 3, 2019 16:06
Create a Solar System.
MERGE (sun:Star { name: "Sun", diameterKm: 1391000, sizeXEarth: 109, massXEarth: 333054, order: 0 })
MERGE (me:Planet { name: "Mercury", diameterKm: 4879, sizeXEarth: 0.4, massXEarth: 0.06, order: 1 })
MERGE (v:Planet { name: "Venus", diameterKm: 12104, sizeXEarth: 0.9, massXEarth: 0.82, order: 2 })
MERGE (e:Planet { name: "Earth", diameterKm: 12756, sizeXEarth: 1, massXEarth: 1, mass: "5.972 × 10^24", order: 3 })
MERGE (ma:Planet { name: "Mars", diameterKm: 6792, sizeXEarth: 0.5, massXEarth: 0.11, order: 4 })
MERGE (j:Planet { name: "Jupiter", diameterKm: 142984, sizeXEarth: 11.2, massXEarth: 317.8, order: 5 })
MERGE (s:Planet { name: "Saturn", diameterKm: 120536, sizeXEarth: 9.4, massXEarth: 95.16, order: 6 })
MERGE (u:Planet { name: "Uranus", diameterKm: 51118, sizeXEarth: 4, massXEarth: 14.54, order: 7 })
MERGE (n:Planet { name: "Neptune", diameterKm: 49528, sizeXEarth: 3.9, massXEarth: 17.15, order: 8 })
MATCH (p)
WHERE p:Star OR p:Planet
WITH min(p.order) as fromN, max(p.order) as toN
UNWIND apoc.coll.pairsMin(range(fromN, toN)) as pair
MATCH (p1 { order: pair[0] })
WHERE p1:Planet OR p1:Star
MATCH (p2:Planet { order: pair[1] })
MERGE (p1)-[:NEXT]->(p2)
MATCH (p)
WHERE p:Planet OR p:Star
WITH toInteger(ceil(p.sizeXEarth * 10)) as size, p
UNWIND range(1, size) as chunk
MERGE (pc:Chunk { n: chunk })-[:OF]->(p)
@vladbatushkov
vladbatushkov / omgc-may-4-1.cypher
Created May 5, 2019 07:41
List all characters involved in Star Wars saga
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.people AS character
RETURN character.name
@vladbatushkov
vladbatushkov / omgc-may-4-2.cypher
Created May 5, 2019 07:42
Main nodes of the saga, includes filmes, characters and planets.
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.films AS film
UNWIND value.people AS character
UNWIND value.planets AS planet
MERGE (:Film { name: film.title, url: film.url })
MERGE (:Character { name: character.name, url: character.url })
MERGE (:Planet { name: planet.name, url: planet.url })
@vladbatushkov
vladbatushkov / omgc-may-4-3.cypher
Created May 5, 2019 07:43
Create species, vehicles and starships.
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.species AS spec
UNWIND value.vehicles AS vehicle
UNWIND value.starships AS starship
MERGE (:Species { name: spec.name, url: spec.url })
MERGE (:Vehicle { name: vehicle.name, url: vehicle.url })
MERGE (:Starship { name: starship.name, url: starship.url })
@vladbatushkov
vladbatushkov / omgc-may-4-4.cypher
Last active May 5, 2019 08:33
Connect characters, planets and scecies with films they are appeared in.
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.films as film
UNWIND film.characters as character_url
MATCH (f:Film { url: film.url })
MATCH (c:Character { url: character_url })
MERGE (c)-[:APPEARED_IN]->(f);
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.films as film
@vladbatushkov
vladbatushkov / omgc-may-4-5.cypher
Last active May 5, 2019 08:26
Connect vehicels nd starships with films they are appeared in.
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.films as film
UNWIND film.starships as starship_url
MATCH (f:Film { url: film.url })
MATCH (s:Starship { url: starship_url })
MERGE (s)-[:APPEARED_IN]->(f);
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.films as film
@vladbatushkov
vladbatushkov / omgc-may-4-6.cypher
Last active May 5, 2019 08:21
Character-related relationships
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.people as character
UNWIND character.species as species_url
MATCH (c:Character { url: character.url })
MATCH (spec:Species { url: species_url })
MERGE (c)-[:OF]->(spec);
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.people as character