
== Import and Export to GraphML

Refers to the issue https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/440[#440] we documented some performance tests of export and import of a big graph
into GraphML format.

== Script to execute all the tests

We created a script that execute all the tests explained below, you can run it like in this example:

[source,bash,subs=attributes]
----
./performanceGraphmlTest.sh 'neo4jHome' 'userName' 'password' 'address'
----

== Export all

[source,cypher]
----
call apoc.export.graphml.all('yourPath/exportAll.graphml',null)
----

=== Results

.no configuration params

----
real    1m25.530s
user    0m0.968s
sys     0m0.068s
----

.useTypes

----
real    1m53.521s
user    0m0.908s
sys     0m0.096s
----

.storeNodeIds

----
real    1m26.898s
user    0m0.900s
sys     0m0.096s
----

.readLabels

----
real    1m30.592s
user    0m0.916s
sys     0m0.116s
----

.defaultRelationshipType

----
real    1m30.829s
user    0m0.928s
sys     0m0.068s
----

.Full config

[source,cypher]
----
call apoc.export.graphml.all('yourPath/exportAll.graphml',{storeNodeIds:true, readLabels:true, useTypes:true, defaultRelationshipType:'RELATED'})
----

== Export GraphML from query

[source,cypher]
----
call apoc.export.graphml.query(
'MATCH (n) OPTIONAL MATCH p = (n)-[r]-(m) RETURN n,r,m',
 'yourPath/exportQuery.graphml', {useTypes:true})
----

=== Results

.no config

----
real    3m2.257s
user    0m0.972s
sys     0m0.084s
----

.useTypes
----
real    3m15.295s
user    0m0.860s
sys     0m0.132s
----

== Export GraphML from Graph object

[source,cypher]
----
CALL apoc.graph.fromDB('test',{}) yield graph
CALL apoc.export.graphml.graph(graph, 'yourPath/exportGraph.graphml',null)
YIELD nodes, relationships, properties, file, source,format, time 
RETURN *
----

=== Results

.no config params

----
real    4m12.586s
user    15m27.490s
sys     0m20.609s
----

.useTypes

----
real    4m44.876s
user    16m46.379s
sys     0m13.421s
----


== Export GraphML from given nodes and rels

[source,cypher]
----
MATCH (n:Person)-[r:LIKES_COMMENT]->(c:Comment)
WITH collect(n) as colN, collect(c) as colC, collect(r) as colR
CALL apoc.export.cypher.data(colN+colC,colR, 'yourPath/exportData.graphml',{useTypes:true})
YIELD nodes, relationships 
RETURN 'none'
----

=== Results

.no config params

----
real    3m54.067s
user    0m6.648s
sys     0m0.496s
----

.useTypes

----
real    4m29.370s
user    0m6.676s
sys     0m0.436s
----

== Import GraphML

Test of import in a blank database of the export files created before

.Only batch size as parameter

[source,cypher]
----
call apoc.import.graphml('yourPath/exportAll.graphml',{batchSize: 10000})
----

----
real    6m50.497s
user    0m1.032s
sys     0m0.084s
----

[options=header]
|===
| file | source | format | nodes | relationships | properties | time | rows
| 'yourPath/exportAll.graphml' | "file" | "graphml" | 3158994 | 16800936 | 42538498 | 409761 | 0
|===

Like we can see from the output we have the same number of nodes and relationship.

.With parameters

[source,cypher]
----
"call apoc.import.graphml('yourPath/exportAllConfig.graphml',
{batchSize: 10000, readLabels: true, storeNodeIds: false, defaultRelationshipType:'RELATED'})
----

----
real    6m44.330s
user    0m0.976s
sys     0m0.100s
----

[options=header]
|===
| file | source | format | nodes | relationships | properties | time | rows
| 'yourPath/exportAll.graphml' | "file" | "graphml" | 3158994 | 16800936 | 22578568 | 403615 | 0
|===

=== Import on Gephi

We tried to import a subset of the graph on **Gephi** :

* 25.000 nodes
* 1.000.000 relationships
* 153.000 properties

image::{img}/import_gephi.png[width=800]

The file has been imported in few seconds.

=== Import on yEd

With the same subset we tried to import it on **yEd**.
The export file has to convert into UTF-8.

image::{img}/import_yed.png[width=800]
