如何使用scala定期提交将csv文件加载到neo4j?

时间:2017-11-14 22:25:22

标签: scala csv neo4j graph-databases

我正在尝试通过从scala代码中将CSV文件加载到neo4j来创建图形。

我使用定期提交导致以下错误:

Exception in thread "main" org.neo4j.driver.v1.exceptions.ClientException: 
Executing queries that use periodic commit in an open transaction is not possible.

有关我为什么会收到此错误以及如何避免错误的任何帮助?我正在使用定期提交,因为我将加载超过100k节点。有定期提交的替代方法吗?

代码:

def createGraph(createStmt: ArrayBuffer[String]): Unit = {
val session = driver.session()
val greeting: String = session.writeTransaction(new TransactionWork[String]() {
  override def execute(transaction: Transaction): String = {
    var result1: StatementResult = transaction.run("USING PERIODIC COMMIT\n"+
                                                  "LOAD CSV WITH HEADERS FROM \"file:///path/to/file.csv\" AS csvLine\n"+
                                                  "CREATE (p:Person {id: toInt(csvLine.id), name: csvLine.name})")

    "Graph Created"
  }
})

}

1 个答案:

答案 0 :(得分:1)

事务上的driver docs表明"自动提交事务是执行USING PERIODIC COMMIT Cypher语句的唯一方法。"

自动提交作为session.run(...)执行,无需使用session.writeTransaction(...启动新事务。)