目录
内文
一、目标:
从csv档汇入Graph Db(Neo4j、ArangoDB、OrientDB)Couple
二、输入:
-
PERSON-资料
-
Relationships (parent,spouse) -关系
三、执行:
Neo4j | query | POST /db/data/transaction/commit(默认数据库),/db/mydb/tx/commit |
{ "statements" : [ { "statement" : "match (n:PERSON {ID:$Id})-[r:PARENT|SPOUSE *..3] -(x) return * limit 100", "parameters" : { "nodeId" : "${id}" }, "resultDataContents" : [ "row", "graph" ] } ] } | ||
import | "bin/neo4j-admin import \ --nodes=import/node_a--relationships=import/rel_a \ --relationships =import/rel_b \ --skip-bad-relationships=true \ --skip-duplicate-nodes=true \ --database= mydb" | |
ArangoDB | 查询 | POST /_api/cursor |
{ "query" : "FOR n IN PERSON FILTER n.ID=='${id}' FOR v, e, p IN 1..3 ANY n GRAPH myGraph LIMIT 100 RETURN p ", "count" : true } | ||
导入节点 | bin/arangoimp --file "/path/file.csv" \ --type csv \ --collection "NODE" \ --server.username user \ --server.password pwd \ --translate "_ID:ID=_key" \ --translate ":TYPE=type" \ --separator="," | |
导入边 | bin/arangoimp - -file "/path/rel_file.csv" \ --type csv \ --collection "EDGE" \ --server.username user \ --server.password pwd \ --separator="," \ --translate ": START_ID=_from" \ --translate ":END_ID=_to" \ --translate ":TYPE=type" \ --translate "LABEL=desc" \ --from-collection-prefix NODE \ --to-collection-prefix NODE \ --ignore-missing true | |
OrientDB | 查询 | GET /query/mydb/sql/ |
SELECT FROM (TRAVERSE in(),out() FROM (SELECT FROM PERSON WHERE ID='$id') MAXDEPTH 3) | ||
导入节点 | { "source ": { "file": { "path": "/path/node.csv" } }, "extractor": { "csv": {} }, "transformers": [ { "vertex": { "class" : "NODE" } } ], "loader": { "orientdb": { "dbURL": "plocal:/path/databases/db", "dbUser": "Admin", "dbPassword": "xxxx", " dbAutoCreate": true, "dbType": "graph", "classes": [ {"name": "NODE", "extends": "V"}, {"name": "EDGE", "extends": " E"} ], "indexes": [ {"class":"PERSON", "fields":["_ID_ID:string"], "type":"UNIQUE" } ] } } } | |
导入边 | { "source": {“文件”:{“路径”:“/path/edge.csv”}}, “提取器”:{“cs v": {} }, "transformers": [ { "merge": { "joinFieldName": "_START_ID", "lookup": "V._ID_ID", "unresolvedLinkAction": "SKIP" } }, { "vertex" : { "class": "NODE", "skipDuplicates": true } }, { "edge": { "class": "EDGE", "joinFieldName": "_END_ID", "lookup": "V._ID_ID", "direction": "out" } } ], "loader": { "orientdb": { "dbURL": "plocal:/path/databases/db", "dbUser": "Admin", "dbPassword": "xxxx ", "dbAutoCreate": true, "dbType": "graph", "classes": [ {"name": "NODE", "extends": "V"}, {"name": "EDGE", "extends ": "E"} ], "indexes": [ {"class":"NODE", "fields":["_ID_ID:string"], "type":"UNIQUE" } ] } } } |
ArangoDB需要
-
在shell中模式才能建立较复杂的图,
-
汇入csv 时需需要关系要与节点的对应关系,
-
可以转移栏位名称
OrientDB
- 使用ETL模式汇入数据
四、输出:
neo4j
arangodb
orientdb
五、参考:
https:/ /www.arangodb.com/docs/stable/programs-arangoimport-examples-csv.html
https://www.arangodb.com/docs/stable/graphs-general-graphs.html
https://www.arangodb.com /2020/05/best-practices-for-aql-graph-queries/
https://neo4j.com/docs/operat ions-manual/current/tools/neo4j-admin-import/
https://neo4j.com/docs/operations-manual/current/tutorial/neo4j-admin-import/
https://neo4j.com/docs/http- api/current/actions/begin-a-transaction/
http://orientdb.org/docs/3.0.x/etl/Loader.html
https://orientdb.org/docs/3.1.x/misc/OrientDB-REST .html
https://stackoverflow.com/questions/33679571/how-to-use-orientdb-etl-to-create-edges-only