-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathassignment12_607.Rmd
More file actions
52 lines (38 loc) · 1.82 KB
/
Copy pathassignment12_607.Rmd
File metadata and controls
52 lines (38 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
title: "Sql to graph"
author: "Alvaro Bueno"
date: "11/17/2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## SQL To Graph walkthrough
By following the Neo4J tutorial, i have a direction on how do do the process, however the COPY command only runs in PostgresQL and not in MYSQL, so in order to export the csv tbales i'm using the following commands and then saving the output to excel.
> echo 'SELECT * FROM votes' | mysql -B -uroot movies
> echo 'SELECT * FROM movies' | mysql -B -uroot movies
> echo 'SELECT * FROM users' | mysql -B -uroot movies
with the 3 CSVs we proceed to create the Neo4J graph, using the following cypher code
```{cypher}
// Create movies
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/delagroove/dataScience/master/movies.csv" AS row
CREATE (:Movie {id: row.id, name: row.name, description: row.description, has_female_lead: row.has_female_lead, genre: row.genre});
// Create users
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/delagroove/dataScience/master/users.csv" AS row
CREATE (:User {id: row.id, name: row.name});
// Create votes
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/delagroove/dataScience/master/votes.csv" AS row
CREATE (:Vote {user_id: row.user_id, movie_id: row.movie_id, rating: row.rating});
CREATE INDEX ON :Movie(id);
CREATE INDEX ON :User(id);
CREATE INDEX ON :Vote(user_id, movie_id);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/delagroove/dataScience/master/votes.csv" AS row
MATCH (user:User {id: row.user_id})
MATCH (movie:Movie {id: row.movie_id})
MERGE (user)-[:VOTE_FOR]->(movie);
```
