Skip to content

Instantly share code, notes, and snippets.

@tkroman
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkroman/aad74c888950b4478bfa to your computer and use it in GitHub Desktop.
Save tkroman/aad74c888950b4478bfa to your computer and use it in GitHub Desktop.
def dumpCypher() {
val createConstraint = """create index on :Node(nid)"""
val dumpNodes =
"""USING PERIODIC COMMIT 5000
|LOAD CSV WITH HEADERS FROM 'file:///home/roman/toDump.csv' AS line
|CREATE (c:Node {title: line.title, nid: toInt(line.nid)})""".stripMargin
val db = new GraphDatabaseFactory().newEmbeddedDatabase("/tmp/skip")
val cypher = new ExecutionEngine(db)
def withTx(b: => Unit) = {
val tx = db.beginTx()
b
tx.success()
tx.close()
}
withTx {
cypher.execute("""CREATE (r:Root:Node {title: "", treeName: "tree", nid: 0})""")
}
cypher.execute(createConstraint)
cypher.execute(dumpNodes)
for (i <- 0 to (550000 / 20000)) {
cypher.execute(
s"""USING PERIODIC COMMIT 5000
|LOAD CSV WITH HEADERS FROM 'file:///home/roman/toDump.csv' AS line
|WITH line SKIP ${i * 20000} limit ${(i + 1) * 20000}
|MATCH
| (parent:Node {nid: toInt(line.pid)}),
| (child: Node {nid: toInt(line.nid)})
|CREATE
| (child)-[:CHILD_OF]->(parent)""".stripMargin
)
}
db.shutdown()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment