Neo4j CSV 导入状态更新
Neo4j CSV import status updates
所以我正在尝试从 Mysql 数据库迁移到 neo4j 数据库。对于新的 neo4j 数据库,我计划了这里解释的新闻源功能 http://neo4j.com/docs/stable/cypher-cookbook-newsfeed.html 这种机制明显不同于 mysql,后者的新闻源只是一堆行。那么有没有一种方法可以将mysql行以-[status_update]->()-[next]->()-
格式快速导入到neo4j中呢?目前我有 mysql 数据库,如下所示:
user table
+-------+--------------+
| id | username |
+-------+--------------+
| 1 | pewpewlasers |
+-------+--------------+
posts table
+-------+----------+------------+
| id | user_id | status |
+-------+----------+------------+
| 1 | 1 | something |
+-------+----------+------------+
| 2 | 1 | new update |
+-------+----------+------------+
如果您将其输出为 CSV 文件,您可以像这样使用 LOAD CSV
:
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/user.csv" AS line
CREATE (:User {id: toInt(line.id), username: line.username});
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/posts.csv" AS line
CREATE (:Post {id: toInt(line.id), line.status});
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/posts.csv" AS line
MATCH (user:User {id: toInt(line.user_id)})
MATCH (post:Post {id: toInt(line.id)})
CREATE user-[:status_update]->post;
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/posts.csv" AS line
MATCH
(post:Post {id: toInt(line.id)})
(previous_post:Post {id: toInt(line.id) - 1})
CREATE previous_post-[:next]->post;
您也许可以组合其中的一些,但由于这里提到的 EAGER 问题,我总是小心地拆分查询:
http://www.markhneedham.com/blog/2014/10/23/neo4j-cypher-avoiding-the-eager/
所以我正在尝试从 Mysql 数据库迁移到 neo4j 数据库。对于新的 neo4j 数据库,我计划了这里解释的新闻源功能 http://neo4j.com/docs/stable/cypher-cookbook-newsfeed.html 这种机制明显不同于 mysql,后者的新闻源只是一堆行。那么有没有一种方法可以将mysql行以-[status_update]->()-[next]->()-
格式快速导入到neo4j中呢?目前我有 mysql 数据库,如下所示:
user table
+-------+--------------+
| id | username |
+-------+--------------+
| 1 | pewpewlasers |
+-------+--------------+
posts table
+-------+----------+------------+
| id | user_id | status |
+-------+----------+------------+
| 1 | 1 | something |
+-------+----------+------------+
| 2 | 1 | new update |
+-------+----------+------------+
如果您将其输出为 CSV 文件,您可以像这样使用 LOAD CSV
:
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/user.csv" AS line
CREATE (:User {id: toInt(line.id), username: line.username});
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/posts.csv" AS line
CREATE (:Post {id: toInt(line.id), line.status});
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/posts.csv" AS line
MATCH (user:User {id: toInt(line.user_id)})
MATCH (post:Post {id: toInt(line.id)})
CREATE user-[:status_update]->post;
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///path/to/file/posts.csv" AS line
MATCH
(post:Post {id: toInt(line.id)})
(previous_post:Post {id: toInt(line.id) - 1})
CREATE previous_post-[:next]->post;
您也许可以组合其中的一些,但由于这里提到的 EAGER 问题,我总是小心地拆分查询:
http://www.markhneedham.com/blog/2014/10/23/neo4j-cypher-avoiding-the-eager/