Import a tree structure

If you have a tree structure in an RDBMS or CSV file and you want to import it in OrientDB, the ETL can come to your rescue. In this example, we use CSV for the sake of simplicity, but it’s the same with JDBC input and a SQL query against an RDBMS.

source.csv

  1. ID,PARENT_ID,LAST_YEAR_INCOME,DATE_OF_BIRTH,STATE
  2. 0,-1,10000,1990-08-11,Arizona
  3. 1,0,12234,1976-11-07,Missouri
  4. 2,0,21322,1978-01-01,Minnesota
  5. 3,0,33333,1960-05-05,Iowa

etl.json

  1. {
  2. "source": { "file": { "path": "source.csv" } },
  3. "extractor": { "row": {} },
  4. "transformers": [
  5. { "csv": {} },
  6. { "vertex": { "class": "User" } },
  7. { "edge": {
  8. "class": "ParentOf",
  9. "joinFieldName": "PARENT_ID",
  10. "direction": "in",
  11. "lookup": "User.ID",
  12. "unresolvedLinkAction": "SKIP"
  13. }
  14. }
  15. ],
  16. "loader": {
  17. "orientdb": {
  18. "dbURL": "plocal:/temp/mydb",
  19. "dbType": "graph",
  20. "classes": [
  21. {"name": "User", "extends": "V"},
  22. {"name": "ParentOf", "extends": "E"}
  23. ], "indexes": [
  24. {"class":"User", "fields":["ID:Long"], "type":"UNIQUE" }
  25. ]
  26. }
  27. }
  28. }