I was exporting my graph using:
graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(new FileOutputStream("/tmp/graph.xml"), graph)
As a result I got an XML node like the following:
<node id="01351655-3a28-492b-961f-94af629a037b">
<data key="labelV">Appointment</data>
<data key="created_onV">1588976206654</data>
<data key="duration">61200000</data>
<data key="name">123</data>
<data key="timestamp_begin">1588716000000</data>
<data key="timestamp_end">1588777200000</data>
<data key="type">OPEN</data>
<data key="updated_by">d522c7c7-d15e-4b6a-bdea-0866efb2ce4a</data>
<data key="updated_onV">1588977412981</data>
</node>
I took the XML file and tried to import it to an empty database using:
graph.io(IoCore.graphml()).reader().create().readGraph(new FileInputStream("/tmp/graph.xml"), graph)
Now in the Gremlin server console I get the following exception:
java.lang.NumberFormatException: For input string: "1588716000000"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.valueOf(Integer.java:983)
at org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLReader.typeCastValue(GraphMLReader.java:324)
at org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLReader.readGraph(GraphMLReader.java:150)
What needs to be done to get this working? I understand there is something wrong with types here. Most importantly I have not modified the exported XML after all.
It is possible that the GraphMLWriter
did not properly identify the range of inputs of your numeric property keys. The writer determines types by simply reading through all the property keys of all the vertices and then checking the type of the first value found for each key. In your case, it's possible that the first value found was an integer but really should have been addressed as long. If you want to avoid such problems (not to mention costly as a full graph scan is essentially required to dynamically determine types), you have the option to specify the edgeKeyTypes(Map)
and vertexKeyTypes(Map)
as part of the GraphMLWriter.Builder
.
gremlin> writer = GraphMLWriter.build().vertexKeyTypes([name:"string",age:"long"]).create()
==>org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLWriter@7d0cd23c
gremlin> g.io("graph.xml").with(IO.writer, writer).write().iterate()
gremlin>
Obviously, you could edit your existing GraphML file to switch the type to "long" and that will allow you to read it in.