| I have the below code in my java program that queries janusgraph to create vertices and edges if they don't exist already. Vertex v1 = g.V().has(<key1>,<value1>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label1>,<key1>,<value1>));
Vertex v2 = g.V().has(<key2>,<value2>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label2>,<key2>,<value2>));
Vertices v1 and v2 get created if they don't exist. ..code to check if an edge exists between the two vertices..
..if there is no edge between the two, create an edge
v1.addEdge(<label3>,v2,<key3>,<value3>)
If the vertices are newly created, the code works fine and the edge also gets created between the two vertices. But if the vertices already exist in the DB, the edge doesn't get created. The difference I could find between the two cases is that v1 and v2 are of 'StandardVertex' type when they are newly created and they are of 'CacheVertex' type when they already exist. 'addEdge' is a valid method in both cases. Yet the edge doesn't get created. |
|
|
Jason Plurad <plu...@...>
You've left out some context here. How are g` and `tx` initialized? Where is the transaction committed?
toggle quoted message
Show quoted text
On Thursday, June 29, 2017 at 10:33:49 AM UTC-4, Teena K wrote: | I have the below code in my java program that queries janusgraph to create vertices and edges if they don't exist already. Vertex v1 = g.V().has(<key1>,<value1>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label1>,<key1>,<value1>));
Vertex v2 = g.V().has(<key2>,<value2>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label2>,<key2>,<value2>));
Vertices v1 and v2 get created if they don't exist. ..code to check if an edge exists between the two vertices..
..if there is no edge between the two, create an edge
v1.addEdge(<label3>,v2,<key3>,<value3>)
If the vertices are newly created, the code works fine and the edge also gets created between the two vertices. But if the vertices already exist in the DB, the edge doesn't get created. The difference I could find between the two cases is that v1 and v2 are of 'StandardVertex' type when they are newly created and they are of 'CacheVertex' type when they already exist. 'addEdge' is a valid method in both cases. Yet the edge doesn't get created. |
|
|
JanusGraph graph = JanusGraphFactory.open("<path>/janusgraph/conf/janusgraph-cassandra.properties"); JanusGraphTransaction tx = graph.newTransaction(); GraphTraversalSource g = graph.traversal();
<code to add vertices and edges>
tx.commit();
The transaction is committed after all the code is executed.
toggle quoted message
Show quoted text
On Thursday, June 29, 2017 at 10:04:20 PM UTC+5:30, Jason Plurad wrote: You've left out some context here. How are g` and `tx` initialized? Where is the transaction committed? On Thursday, June 29, 2017 at 10:33:49 AM UTC-4, Teena K wrote: | I have the below code in my java program that queries janusgraph to create vertices and edges if they don't exist already. Vertex v1 = g.V().has(<key1>,<value1>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label1>,<key1>,<value1>));
Vertex v2 = g.V().has(<key2>,<value2>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label2>,<key2>,<value2>));
Vertices v1 and v2 get created if they don't exist. ..code to check if an edge exists between the two vertices..
..if there is no edge between the two, create an edge
v1.addEdge(<label3>,v2,<key3>,<value3>)
If the vertices are newly created, the code works fine and the edge also gets created between the two vertices. But if the vertices already exist in the DB, the edge doesn't get created. The difference I could find between the two cases is that v1 and v2 are of 'StandardVertex' type when they are newly created and they are of 'CacheVertex' type when they already exist. 'addEdge' is a valid method in both cases. Yet the edge doesn't get created. |
|
|
David Pitera <piter...@...>
So I am not sure this will fix your problem, but please give it a try and let me know if it does:
toggle quoted message
Show quoted text
On Fri, Jun 30, 2017 at 12:43 AM, Teena K <avidlea...@...> wrote: JanusGraph graph = JanusGraphFactory.open("<path> /janusgraph/conf/janusgraph- cassandra.properties"); JanusGraphTransaction tx = graph.newTransaction(); GraphTraversalSource g = graph.traversal();
<code to add vertices and edges>
tx.commit();
The transaction is committed after all the code is executed. On Thursday, June 29, 2017 at 10:04:20 PM UTC+5:30, Jason Plurad wrote: You've left out some context here. How are g` and `tx` initialized? Where is the transaction committed? On Thursday, June 29, 2017 at 10:33:49 AM UTC-4, Teena K wrote: | I have the below code in my java program that queries janusgraph to create vertices and edges if they don't exist already. Vertex v1 = g.V().has(<key1>,<value1>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label1>,<key1>,<value1>));
Vertex v2 = g.V().has(<key2>,<value2>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label2>,<key2>,<value2>));
Vertices v1 and v2 get created if they don't exist. ..code to check if an edge exists between the two vertices..
..if there is no edge between the two, create an edge
v1.addEdge(<label3>,v2,<key3>,<value3>)
If the vertices are newly created, the code works fine and the edge also gets created between the two vertices. But if the vertices already exist in the DB, the edge doesn't get created. The difference I could find between the two cases is that v1 and v2 are of 'StandardVertex' type when they are newly created and they are of 'CacheVertex' type when they already exist. 'addEdge' is a valid method in both cases. Yet the edge doesn't get created. |
|
|
One problem is that you are mixing APIs. There is a direction in TinkerPop to even further separate the lines between user Traversal API and implementer Graph API. So it is highly recommend to stick with the user Traversal API. Here is the equivalent gremlin:
gremlin> g = TinkerGraph.open().traversal() ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
// starting with an empty graph gremlin> g.V() gremlin> g.E()
// get or create all vertexes and edges gremlin> g.inject(1).coalesce( __.V().has('person','name','marko'), __.addV('person').property('name','marko')).as('marko'). coalesce( __.V().has('person','name','stephen'), __.addV('person').property('name','stephen')).as('stephen'). coalesce( __.in('knows').has('person','name','marko'), __.addE('knows').from('marko')) ==>e[4][0-knows->2]
// show the path that now exists gremlin> g.V().outE().inV().path().by(valueMap(true)) ==>[[name:[marko],label:person,id:0],[label:knows,id:4],[name:[stephen],label:person,id:2]]
// run it again, nothing new should be created gremlin> g.inject(1).coalesce(__.V().has('person','name','marko'),__.addV('person').property('name','marko')).as('marko').coalesce(__.V().has('person','name','stephen'),__.addV('person').property('name','stephen')).as('stephen').coalesce(__.in('knows').has('person','name','marko'),__.addE('knows').from('marko')) ==>v[0]
// show that only the previous relations exist, nothing new gremlin> g.V().outE().inV().path().by(valueMap(true)) ==>[[name:[marko],label:person,id:0],[label:knows,id:4],[name:[stephen],label:person,id:2]]
--
Robert Dale
toggle quoted message
Show quoted text
On Thursday, June 29, 2017 at 10:33:49 AM UTC-4, Teena K wrote: | I have the below code in my java program that queries janusgraph to create vertices and edges if they don't exist already. Vertex v1 = g.V().has(<key1>,<value1>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label1>,<key1>,<value1>));
Vertex v2 = g.V().has(<key2>,<value2>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label2>,<key2>,<value2>));
Vertices v1 and v2 get created if they don't exist. ..code to check if an edge exists between the two vertices..
..if there is no edge between the two, create an edge
v1.addEdge(<label3>,v2,<key3>,<value3>)
If the vertices are newly created, the code works fine and the edge also gets created between the two vertices. But if the vertices already exist in the DB, the edge doesn't get created. The difference I could find between the two cases is that v1 and v2 are of 'StandardVertex' type when they are newly created and they are of 'CacheVertex' type when they already exist. 'addEdge' is a valid method in both cases. Yet the edge doesn't get created. |
|
|
Teena:
How do you fix this problem? I'm boring about it.
toggle quoted message
Show quoted text
On Friday, June 30, 2017 at 12:43:27 PM UTC+8, Teena K wrote: JanusGraph graph = JanusGraphFactory.open("<path> /janusgraph/conf/janusgraph- cassandra.properties"); JanusGraphTransaction tx = graph.newTransaction(); GraphTraversalSource g = graph.traversal();
<code to add vertices and edges>
tx.commit();
The transaction is committed after all the code is executed. On Thursday, June 29, 2017 at 10:04:20 PM UTC+5:30, Jason Plurad wrote: You've left out some context here. How are g` and `tx` initialized? Where is the transaction committed? On Thursday, June 29, 2017 at 10:33:49 AM UTC-4, Teena K wrote: | I have the below code in my java program that queries janusgraph to create vertices and edges if they don't exist already. Vertex v1 = g.V().has(<key1>,<value1>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label1>,<key1>,<value1>));
Vertex v2 = g.V().has(<key2>,<value2>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label2>,<key2>,<value2>));
Vertices v1 and v2 get created if they don't exist. ..code to check if an edge exists between the two vertices..
..if there is no edge between the two, create an edge
v1.addEdge(<label3>,v2,<key3>,<value3>)
If the vertices are newly created, the code works fine and the edge also gets created between the two vertices. But if the vertices already exist in the DB, the edge doesn't get created. The difference I could find between the two cases is that v1 and v2 are of 'StandardVertex' type when they are newly created and they are of 'CacheVertex' type when they already exist. 'addEdge' is a valid method in both cases. Yet the edge doesn't get created. |
|
|