Titan graph (embedded Cassandra - Elasticsearch), Import CSV files using existing external indexed property keys

StackOverflow https://stackoverflow.com/questions/22209730

Question

I need to figure out how to import CSV files using pre-defined indexed property keys, I tried this:

With a empty Titan graph this code works perfectly

new File("/home/User/titan-server-0.4.2/propnodes.csv").eachLine{ line -> (BaseRecId,StreetNumber,StreetName,StreetSuffix,City,County,State,Zip) = line.split(",");

prop = g.addVertex("BaseRecId::"+BaseRecId);

ElementHelper.setProperties(prop, ["BaseRecId" : BaseRecId,"StreetNumber": StreetNumber,"StreetName" : StreetName,"StreetSuffix" : StreetSuffix,"City" : City,"County": County,"State" : State,"Zip" : Zip])}

Now, due Titan indexes need to be setup before to populate any data, first step I do this:

g.makeKey('BaseRecId').dataType(Integer.class).indexed('search', Vertex.class).make(); g.makeKey('StreetName').dataType(String.class).indexed('search', Vertex.class).make();

and then when I try to import the data with the above code, and I got this error

An error occurred while processing the script for language [groovy]. All transactions across all graphs in the session have been concluded with failure: javax.script.ScriptException: javax.script.ScriptException: java.lang.NumberFormatException: For input string: "BaseRecId"

How can I import CSV files using existing external indexed property Keys?

Was it helpful?

Solution

You defined BaseRecId as an integer but you are trying to push it in as a string. Your code should look something like this:

ElementHelper.setProperties(prop, ["BaseRecId" : Integer.parseInt(BaseRecId),"StreetNumber": StreetNumber,"StreetName" : StreetName,"StreetSuffix" : StreetSuffix,"City" : City,"County": County,"State" : State,"Zip" : Zip])}

Also g.addVertex will not respect that ID you are passing it. Titan does not allow for user supplied ids. Finally, you might consider using groovy-csv for working with CSV files in the Gremlin REPL.

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