Last active
August 29, 2015 14:04
-
-
Save tkroman/aad74c888950b4478bfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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