【发布时间】:2015-11-11 16:51:41
【问题描述】:
我在使用 Blueprint Java API 在 OrientDB 中的数据摄取非常缓慢。
具体来说,我使用plocal 模式和OrientGraphNoTx 类从几个CSV 文件中加载~1M 节点和3M 边(不幸的是我不能使用ETL,因为它不允许我读取包含边的文件在现有节点之间)。
代码用 Scala 编写,运行大约一个半小时。
数据库的模式包含 5 个顶点类、7 个边类和 6 个索引。我用来创建边的属性使用unique_hash_indexes 进行索引。
在现有节点之间创建边是最耗时的操作(可能是因为边很多),下面是我使用的代码。
有人知道如何优化它吗?
/**
* Adds edges to the graph.
* Assumes edgesPath points to a CSV file with format (from, to)
*/
def addEdges(edgesPath: String,
fromTable: String, fromAttribute: String,
toTable: String, toAttribute: String,
edgeType: String, graph: OrientGraphNoTx) {
logger.info(s"Adding edges from '$edgesPath'...")
val in = Files.newBufferedReader(Paths.get(edgesPath), Charset.forName("utf-8"))
val records = CSVFormat.DEFAULT
.withHeader("from", "to")
.withSkipHeaderRecord(hasHeader)
.parse(in)
var errors = 0
for (r <- records) {
val (src, target) = (r.get("from"), r.get("to"))
if (src != "" && target != "") {
try {
graph.command(new OCommandSQL(s"CREATE EDGE $edgeType FROM (" +
s"SELECT FROM $fromTable WHERE $fromAttribute = '$src') " +
s"TO (SELECT FROM $toTable WHERE $toAttribute ='$target')")).execute()
} catch {
case e: OCommandExecutionException => errors += 1
}
} //if
} //for
if(errors > 0)
logger.warn(s"Couldn't create $errors edges due to missing sources/targets or internal errors")
logger.info("done.")
} //addEdges
【问题讨论】:
标签: orientdb tinkerpop-blueprint