Question

I'm trying to load a tinkerpop db saved using TinkerGraph.FileType.GRAPHML type.

This is my code:

public Graph getDatabase(String path) {
    org.apache.commons.configuration.Configuration conf = new BaseConfiguration();
    conf.setProperty("blueprints.tg.directory", path);
    conf.setProperty("blueprints.tg.file-type", "GRAPHML");
    conf.setProperty("blueprints.graph", "com.tinkerpop.blueprints.impls.tg.TinkerGraph");
    return GraphFactory.open(conf);
}

This code give me a java.lang.RuntimeException: GraphFactory could not instantiate this Graph implementation [com.tinkerpop.blueprints.impls.tg.TinkerGraph].

The cause is a number format exception

Caused by: java.lang.NumberFormatException: For input string: "2306416072"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.valueOf(Integer.java:582)
at com.tinkerpop.blueprints.util.io.graphml.GraphMLReader.typeCastValue(GraphMLReader.java:313)
at com.tinkerpop.blueprints.util.io.graphml.GraphMLReader.inputGraph(GraphMLReader.java:252)
at com.tinkerpop.blueprints.util.io.graphml.GraphMLReader.inputGraph(GraphMLReader.java:116)
at com.tinkerpop.blueprints.impls.tg.TinkerStorageFactory$GraphMLTinkerStorage.loadGraphData(TinkerStorageFactory.java:187)
at com.tinkerpop.blueprints.impls.tg.TinkerStorageFactory$AbstractSeparateTinkerStorage.load(TinkerStorageFactory.java:94)
at com.tinkerpop.blueprints.impls.tg.TinkerGraph.init(TinkerGraph.java:134)
... 51 more

I searched "2306416072" in the xml file (database). It's a property id <-data key="user_id"->2306416072<-/data->

don't know why i'm getting a number format exception. I navigate in the class GraphMLReader and this is the method

private static Object typeCastValue(String key, String value, Map<String, String> keyTypes) {
    String type = keyTypes.get(key);
    if (null == type || type.equals(GraphMLTokens.STRING))
         return value;
    else if (type.equals(GraphMLTokens.FLOAT)) 
         return Float.valueOf(value);
    else if (type.equals(GraphMLTokens.INT)) 
         return Integer.valueOf(value);
    else if (type.equals(GraphMLTokens.DOUBLE)) 
         return Double.valueOf(value);
    else if (type.equals(GraphMLTokens.BOOLEAN)) 
         return Boolean.valueOf(value);
    else if (type.equals(GraphMLTokens.LONG)) 
         return Long.valueOf(value);
    else 
        return value;
}
Was it helpful?

Solution

Integer.MAX_VALUE is 2147483647 (that's obviously less than 2306416072). I think the reader is not the problem; either writing went wrong or you manually added some new elements to your XML file and forgot to update the type definition. I think the latter is the case, because I just tried the following:

gremlin> g = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]
gremlin> g.addVertex(["num":123])
==>v[0]
gremlin> g.addVertex(["num":2306416072])
==>v[1]
gremlin> g.v(0).num.getClass()
==>class java.lang.Integer
gremlin> g.v(1).num.getClass()
==>class java.lang.Long
gremlin> g.saveGraphML("/tmp/numtest.xml")
==>null

gremlin> h = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]
gremlin> h.loadGraphML("/tmp/numtest.xml")
==>null
gremlin> h.V().map()
==>{num=2306416072}
==>{num=123}
gremlin> h.v(0).num.getClass()
==>class java.lang.Long
gremlin> h.v(1).num.getClass()
==>class java.lang.Long

How does the type definition at the beginning of your XML look like? For the numtest.xml created above it's:

<key id="num" for="node" attr.name="num" attr.type="long"></key>

Cheers, Daniel

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top