Skip to content

Instantly share code, notes, and snippets.

@xdelox
Last active February 8, 2021 11:20
Show Gist options
  • Save xdelox/ad0882ee1f09293b0b9f1f3f9989fc9c to your computer and use it in GitHub Desktop.
Save xdelox/ad0882ee1f09293b0b9f1f3f9989fc9c to your computer and use it in GitHub Desktop.
Import Movie Database from CSV
call apoc.periodic.iterate(
"call apoc.load.csv('movies2.csv', { mapping:{
movieId : { type: 'int' },
releaseYear: { type: 'int' },
personId: { type: 'int' },
birthYear: { type: 'int' },
deathYear: { type: 'int' }
}
}) yield map return map",
"merge (m:Movie {id: map.movieId}) set m.title = map.title, m.avgVote = map.avgVote, m.tagline = map.tagline
foreach (genre in apoc.text.split(map.genres, ':') |
merge (g:Genre {name: genre})
merge (m)-[:GENRE]->(g))
merge (p:Person {id: map.personId})
SET p.name = map.name,
p.birthYear = map.birthYear,
p.deathYear = map.deathYear
WITH map, m, p
call apoc.do.case([
map.personType = 'ACTOR', 'with p, m, apoc.text.split(map.characters, \":\") as charcts
merge (p)-[a:ACTED_IN {roles: charcts}]->(m) return a',
map.personType = 'DIRECTOR', 'merge (p)-[d:DIRECTED]->(m) return d'
],'', {map:map, m:m, p:p}) yield value
match (n:Person { deathYear : 0 }) remove n.deathYear",
{batchSize:500, parallel:false})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment