简体   繁体   中英

OrientDB: Create Edges with subselect

I have a simple tree structure in a MySQL table (id, parentId) with about 3 million vertices and wanted to import this into a OrientDB Graph database. The ETL importer imports the vertices smoothly, but can't create edges (NullPointerException). The ETL does not even work on a plain database with the given examples in the documentation ( http://orientdb.com/docs/last/Import-a-tree-structure.html throws the same exception), so I just imported the vertices and wanted to create the edges manually.

I have a Vertex class (Address) with two properties (id, parentId) and I want to create the Edges between these Vertices (parentId -> id). Is there a simple way to do this instead of inserting the edges in a loop? Something like in SQL

INSERT INTO E (out, in) VALUES (SELECT parentId, id FROM Address)

Since edges shall only be created with CREATE EDGE, I guess OrientDB does not support such an operation by default. But maybe there is a workaround to create these 3 million edges?

I found it is easy to create a link between the two records:

CREATE LINK parentLink TYPE LINK FROM Address.parentId TO Address.Id

However, I cannot create Edges in such a way. I tried working with variables

CREATE EDGE isParentOf FROM (SELECT FROM Address) TO (SELECT FROM Address WHERE id = $current.parentId)

But that does not work.

Have you tried this ETL Json:

{
  "config": {"log": "debug", "parallel": true },    
  "extractor" : {
    "jdbc": { "driver": "oracle.jdbc.driver.OracleDriver",
              "url": "jdbc:oracle:thin:hostname/db",    
              "userName": "username",    
              "userPassword": "password",    
              "query": "select id, A.parentId from Address a where rownum<2"     }    
  },    
  "transformers": [`enter code here`

    { "vertex": { "class": "Address" }},

    { "edge": { "class": "isParentOf",
      "joinFieldName": "parentId",
      "lookup": "Address.Id",
      "direction": "in",
      "skipDuplicates":true
    }
    }
    ],
    "loader": {
    "orientdb": {
      "dbURL": "remote:server/db",
      "dbUser": "user",
      "dbPassword": "passwd!",
      "dbType": "graph",
      "classes": [
        {"name": "Address", "extends": "V"},
        {"name": "isParentOf", "extends": "E"}
      ], "indexes": [
        {"class":"Address", "fields":["ID:string"], "type":"UNIQUE" }
      ]
    }
  }
}

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