In this challenge, you will update the import to add new properties to the Movie
nodes and cast them to the correct type.
Previously, you used the following Cypher statement to import the Movie
nodes:
LOAD CSV WITH HEADERS
FROM 'https://data.neo4j.com/importing-cypher/movies.csv'
AS row
MERGE (m:Movie {movieId: toInteger(row.movieId)})
SET
m.tmdbId = toInteger(row.movie_tmdbId),
m.imdbId = toInteger(row.movie_imdbId),
m.released = row.released,
m.title = row.title,
m.year = row.year,
m.plot = row.plot,
m.budget = row.budget
The year
and budget
properties are not cast and therefore stored as strings.
Update and run the existing import to cast the year
and budget
properties to integers using the toInteger()
function.
LOAD CSV WITH HEADERS
FROM 'https://data.neo4j.com/importing-cypher/movies.csv'
AS row
MERGE (m:Movie {movieId: toInteger(row.movieId)})
SET
m.tmdbId = toInteger(row.movie_tmdbId),
m.imdbId = toInteger(row.movie_imdbId),
m.released = row.released,
m.title = row.title,
m.year = toInteger(row.year),
m.plot = row.plot,
m.budget = toInteger(row.budget)
The movies.csv
file also contains the following additional properties:
-
imdbRating
-
poster
-
runtime
-
imdbVotes
-
revenue
-
url
Review the data in the file and identify the data type and cast function for each property.
Reveal the data types and functions
Property |
Data type |
Cast function |
|
Float |
|
|
String |
|
|
Integer |
|
|
Integer |
|
|
Integer |
|
|
String |
Finally, update the import to add these properties to the Movie
nodes and cast them to the correct type.
Validate Movie properties
Once you have updated the Movie
properties to use the correct data type, click the Check Database button to verify that the task is complete.
Hint
Modify the Movie
import Cypher to cast the properties to the correct type.
Solution
Run this Cypher statement to update the Movie
properties to use the correct data type.
LOAD CSV WITH HEADERS
FROM 'https://data.neo4j.com/importing-cypher/movies.csv' AS row
MERGE (m:Movie {movieId: toInteger(row.movieId)})
SET
m.tmdbId = toInteger(row.movie_tmdbId),
m.imdbId = toInteger(row.movie_imdbId),
m.released = date(row.released),
m.title = row.title,
m.year = toInteger(row.year),
m.plot = row.plot,
m.budget = toInteger(row.budget),
m.imdbRating = toFloat(row.imdbRating),
m.poster = row.poster,
m.runtime = toInteger(row.runtime),
m.imdbVotes = toInteger(row.imdbVotes),
m.revenue = toInteger(row.revenue),
m.url = row.url
Summary
In this lesson, you applied what you learned from the previous lesson and cast properties to the correct data type.
In the next lesson, you will learn how to create list properties.