I am using following script in gremlin to create a graph by using csv file:
graph = TinkerGraph.open()
graph.createIndex('userId', Vertex.class) //(1)
g = graph.traversal()
getOrCreate = { id ->
g.V().has('userId', id).tryNext().orElseGet{ g.addV('userId', id).next() }
}
new File('wiki-Vote.txt').eachLine
{
if (!it.startsWith("#")){
l->p=it.split(',').collect(getOrCreate) //(2)**
(fromVertex, toVertex) = (s[0],s[1])
fromVertex.addEdge('votesFor', toVertex) } }
as we can see in this query see line
l>p=it.split(',').collect(getOrCreate)
in this line the csv file rows are splitting based on delimiter "," then the getOrCreate method function is called to apply indexing on the collected vertices.
if I give g.V().count() it is counting the all the values in all columns. but I need to add only selected columns into vertex.
what I need: I want to apply getOrCreate method only on selected columns instead of applying on all columns
for example:if csv file has name, age,Id,marks columns. I want to apply getOrCreate method only on name and age columns and add these into vertex. if I give g.V().count()... it has to give me only name and age counts