简体   繁体   中英

How import CSV using JSON in OrientDB using ID from one table and the values of another?

I have 3 CSV files: one for node A, one for node B and one for edge A_to_B.

I can import the nodes into OrientDB just fine. It's the edges that I'm having problems with.

node a's CSV file contains (where id is integer index):

id, value
0, a
1, b
2, c
3, d
...

node b's CSV file contains (where id is a integer index):

id, Category
10, cat_x
11, cat_y
12, cat_z

edge_a_b CSV contains:

a_id, Category
0, cat_x
1, cat_z
2, cat_z
...

I can get the two "a" and "b" properly into the database. However, when I run this ETL json...

{
  "source": { "file": { "path": "/mypath/edge_a_b.csv" } },
  "extractor": { "csv": {} },
  "transformers": [
    { "vertex": { "class": "b", "skipDuplicates": true } },
    { "edge": { "class": "Involves", "joinFieldName": "a_id", "lookup": "a.id", "direction": "in" } }
  ],
  "loader": {
    "orientdb": {
       "dbURL": "plocal:../databases/mydb",
       "dbType": "graph",
       "classes": [
         {"name": "a", "extends": "V"},
         {"name": "b", "extends": "V"},
         {"name": "Involves", "extends": "E"}
       ], "indexes": [
         {"class":"a", "fields":["id:integer"], "type":"UNIQUE" },
         {"class":"b", "fields":["id:integer"], "type":"UNIQUE" }
       ]
    }
  }
}

I only get 1 of the 215 vertices I'm expecting matched.

| => ./oetl.sh /mypath/edge_a_b.json

OrientDB etl v.2.2.11 (build 2.2.x@r8b3a478e3ca7321a48e7cf0f5991569bbe06ed89; 2016-10-03 09:39:41+0000) www.orientdb.com
BEGIN ETL PROCESSOR
[file] INFO Reading from file /mypath/edge_a_b.csv with encoding UTF-8
Started execution with 1 worker threads
[orientdb] INFO committing
END ETL PROCESSOR
+ extracted 215 rows (0 rows/sec) - 215 rows -> loaded 1 vertices (0 vertices/sec) Total time: 172ms [0 warnings, 0 errors]

I have the nodes created. It's the edges that I'm finding difficult to create. I've tried various approaches.

You could use

 "extractor": {"row": {}},
    "transformers": [{
            "csv": {
                "separator": ","
            }
        },
        {
        "command" : {
                "command" : "create edge Involves from (select from a where id= ${input.a_id}) to (select from b where Category= '${input.Category}')",
                "output" : "edge"
            }
        }
      ],

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM