OrientDB导入Neo4j(官方Importer使用)

前端之家收集整理的这篇文章主要介绍了OrientDB导入Neo4j(官方Importer使用)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

最近在研究图计算相关技术,前一阶段学了Neo4j的知识,在学习的过程也对比一些其它的开源图数据库,如OrientDB,还有一些通用框架TinkerPop。

在OrientDB的对比学习过程中,希望首先把已有的数据导入到新的数据库中,还好OrientDB官方提供了Neo4j数据导入工具orientdb-neo4j-importer。然而一切皆有坑...

按照官方文档进行数据导入,执行命令:

  1. sh orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/

出现以下报错:

  1. Exception in thread "main" java.lang.NoClassDefFoundError: com/orientechnologies/orient/core/OConstants
  2. at com.orientechnologies.orient.neo4jimporter.ONeo4jImporterMain.main(ONeo4jImporterMain.java:15)
  3. Caused by: java.lang.ClassNotFoundException: com.orientechnologies.orient.core.OConstants
  4. at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  5. at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  6. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  7. at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  8. ... 1 more

尝试把importer/lib/orientdb-neo4j-importer-2.2.31.jar拷贝到orientdb安装目录的lib文件夹下,再次执行还是同样的报错。

查看源代码也没发现此处有问题,再通过sh打印详细信息发现环境变量ORIENTDB_HOME设置有问题,执行以下命令定义环境变量:

  1. export ORIENTDB_HOME=/root/orientdb-community-importers-2.2.31

再次执行命令,顺利通过!

  1. [root@datanode orientdb-community-importers-2.2.31]# sh -x orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/
  2. + PRG=orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh
  3. + '[' -h orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh ']'
  4. ++ dirname orientdb-neo4j-importer-2.2.31/bin/orientdb-neo4j-importer.sh
  5. + PRGDIR=orientdb-neo4j-importer-2.2.31/bin
  6. + '[' -f /root/orientdb-community-importers-2.2.31/lib/orientdb-neo4j-importer-2.2.31.jar ']'
  7. + export ORIENTDB_HOME
  8. + '[' -f /usr/java/jdk1.8.0_91/bin/java ']'
  9. + JAVA=/usr/java/jdk1.8.0_91/bin/java
  10. + export JAVA
  11. + LOG_FILE=/root/orientdb-community-importers-2.2.31/config/orientdb-neo4j-importer-log.properties
  12. + JAVA_MAX_DIRECT=-XX:MaxDirectMemorySize=512g
  13. + JAVA_OPTS_SCRIPT='-XX:MaxDirectMemorySize=512g -Djava.util.logging.config.file=/root/orientdb-community-importers-2.2.31/config/orientdb-neo4j-importer-log.properties'
  14. + ARGS=
  15. + for var in '"$@"'
  16. + ARGS=' -neo4jdbdir'
  17. + for var in '"$@"'
  18. + ARGS=' -neo4jdbdir ../graph.db/'
  19. + for var in '"$@"'
  20. + ARGS=' -neo4jdbdir ../graph.db/ -neo4jlibdir'
  21. + for var in '"$@"'
  22. + ARGS=' -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/'
  23. + [[ 4 -gt 1 ]]
  24. + key=-neo4jdbdir
  25. + case $key in
  26. + shift
  27. + [[ 3 -gt 1 ]]
  28. + key=../graph.db/
  29. + case $key in
  30. + shift
  31. + [[ 2 -gt 1 ]]
  32. + key=-neo4jlibdir
  33. + case $key in
  34. + NEO4JLIB=../neo4jlib/
  35. + shift
  36. + shift
  37. + [[ 0 -gt 1 ]]
  38. + exec /usr/java/jdk1.8.0_91/bin/java -client -cp '../neo4jlib//*:/root/orientdb-community-importers-2.2.31/lib/*' -XX:MaxDirectMemorySize=512g -Djava.util.logging.config.file=/root/orientdb-community-importers-2.2.31/config/orientdb-neo4j-importer-log.properties com.orientechnologies.orient.neo4jimporter.ONeo4jImporterMain -neo4jdbdir ../graph.db/ -neo4jlibdir ../neo4jlib/
  39.  
  40. Neo4j to OrientDB Importer v.2.2.31 (build 285537d2767275f460df32c6a3be01bfff6a517c,branch 2.2.x) - Copyrights (c) 2016 OrientDB LTD
  41.  
  42. WARNING: 'o' option not found. Defaulting to 'false'.
  43.  
  44. WARNING: 'i' option not found. Defaulting to 'false'.
  45.  
  46. WARNING: 'odbdir' option not found. Defaulting to '/root/databases/neo4j_import'.
  47.  
  48. Please make sure that there are no running servers on:
  49. '../graph.db' (Neo4j)
  50. and:
  51. '/root/databases/neo4j_import' (OrientDB)
  52.  
  53. Initializing Neo4j...Done
  54.  
  55. Initializing OrientDB...Done
  56.  
  57. Importing Neo4j database:
  58. '../graph.db'
  59. into OrientDB database:
  60. '/root/databases/neo4j_import'
  61.  
  62. Getting all Nodes from Neo4j and creating corresponding Vertices in OrientDB...
  63. 4 OrientDB Vertices have been created (100% done)
  64. Done
  65.  
  66. Creating internal Indices on properties 'Neo4jNodeID' & 'Neo4jLabelList' on all OrientDB Vertices Classes...
  67. 4 OrientDB Indices have been created (100% done)
  68. Done
  69.  
  70. Getting all Relationships from Neo4j and creating corresponding Edges in OrientDB...
  71. 2 OrientDB Edges have been created (100% done)
  72. Done
  73.  
  74. Getting Constraints from Neo4j and creating corresponding ones in OrientDB...
  75. 0 OrientDB UNIQUE Indices have been created
  76. Done
  77.  
  78. Getting Indices from Neo4j and creating corresponding ones in OrientDB...
  79. 0 OrientDB Indices have been created
  80. Done
  81.  
  82. Import completed!
  83.  
  84. Shutting down OrientDB...Done
  85. Shutting down Neo4j...Done
  86.  
  87. ===============
  88. Import Summary:
  89. ===============
  90.  
  91. - Found Neo4j Nodes : 4
  92. -- With at least one Label : 4
  93. --- With multiple Labels : 0
  94. -- Without Labels : 0
  95. - Imported OrientDB Vertices : 4 (100%)
  96.  
  97. - Found Neo4j Relationships : 2
  98. - Imported OrientDB Edges : 2 (100%)
  99.  
  100. - Found Neo4j Constraints : 0
  101. - Imported OrientDB Constraints (UNIQUE Indices created) : 0
  102. - NOT UNIQUE Indices created due to failure in creating UNIQUE Indices : 0
  103.  
  104. - Found Neo4j (non-constraint) Indices : 0
  105. - Imported OrientDB Indices : 0
  106.  
  107. - Additional internal Indices created : 4
  108.  
  109. - Total Import time: : 6 seconds
  110. -- Initialization time : 5 seconds
  111. -- Time to Import Nodes : 0 seconds (35.4 nodes/sec)
  112. -- Time to Import Relationships : 0 seconds (22.47 rels/sec)
  113. -- Time to Import Constraints and Indices : 0 seconds (0 indices/sec)
  114. -- Time to Create Internal Indices (on vertex properties 'Neo4jNodeID' & 'Neo4jLabelList') : 1 seconds (7.01 indices/sec)

以为一切搞定,启动OrientDB数据库,并没有看到新导入的数据库... 再仔细查看发现没有添加选项-odbdir(但是默认值应该是DB_HOME/databases/neo4j_import,不知道为何没有生效...),数据库导入到其它路径下,拷贝过来后可以正常使用了。

(如图,neo4j_import数据库

猜你在找的NoSQL相关文章